> ## Documentation Index
> Fetch the complete documentation index at: https://docs.optimism.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Consensus

The `op-alloy-consensus` crate provides an Optimism consensus interface.
It contains constants, types, and functions for implementing Optimism EL
consensus and communication. This includes an extended `OpTxEnvelope` type
with [deposit transactions](https://specs.optimism.io/protocol/deposits.html), and receipts containing OP Stack
specific fields (`deposit_nonce` + `deposit_receipt_version`).

In general a type belongs in this crate if it exists in the
`alloy-consensus` crate, but was modified from the base Ethereum protocol
in the OP Stack. For consensus types that are not modified by the OP Stack,
the `alloy-consensus` types should be used instead.

## Block

[`op-alloy-consensus`](https://crates.io/crates/op-alloy-consensus) exports an Optimism block type, [`OpBlock`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/type.OpBlock.html).

This type simply re-uses the `alloy-consensus` block type, with `OpTxEnvelope`
as the type of transactions in the block.

## Transactions

Optimism extends the Ethereum [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) transaction envelope to include a
deposit variant.

### [`OpTxEnvelope`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/transaction/enum.OpTxEnvelope.html)

The [`OpTxEnvelope`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/transaction/enum.OpTxEnvelope.html) type is based on [Alloy](https://github.com/alloy-rs/alloy)'s
[`TxEnvelope`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/transaction/enum.OpTxType.html) type.

Optimism modifies the `TxEnvelope` to the following.

* Legacy
* EIP-2930
* EIP-1559
* EIP-7702
* Deposit

Deposit is a custom transaction type that is either an L1 attributes
deposit transaction or a user-submitted deposit transaction. Read more
about deposit transactions in [the specs](https://specs.optimism.io).

### Transaction Types ([`OpTxType`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/transaction/enum.OpTxType.html))

The [`OpTxType`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/transaction/enum.OpTxType.html) enumerates the transaction types using their byte identifier,
represents as a `u8` in rust.

## Receipt Types

Just like [`op-alloy-consensus`](https://crates.io/crates/op-alloy-consensus) defines transaction types,
it also defines associated receipt types.

[`OpReceiptEnvelope`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/enum.OpReceiptEnvelope.html) defines an [Eip-2718](https://eips.ethereum.org/EIPS/eip-2718) receipt envelope type
modified for the OP Stack. It contains the following variants - mapping
directly to the `OpTxEnvelope` variants defined above.

* Legacy
* EIP-2930
* EIP-1559
* EIP-7702
* Deposit

There is also an [`OpDepositReceipt`](https://docs.rs/op-alloy-consensus/latest/op_alloy_consensus/struct.OpDepositReceipt.html) type, extending the alloy receipt
type with a deposit nonce and deposit receipt version.
