Skip to content

Commit df0a839

Browse files
authored
docs: cover protocol types and PeerDAS (#181)
## Summary - map primitives, consensus, EIP, network, RPC, genesis, trie, and serde types to their intended boundaries - explain how RPC responses embed consensus values and which conversions preserve or discard metadata - document network-associated types, chain-specific implementations, persistence choices, and constrained builds - add EIP-7594 PeerDAS sidecar coverage to the transaction guide and navigation ## Why The site documents primitives and provider calls but does not explain the protocol and data-model crates that make up much of Alloy. Users must infer when to use consensus versus RPC types, how Network changes associated types, and where genesis, trie, and serialization helpers fit. The examples include EIP-7594, but the transaction guide omits it. ## Impact Infrastructure and library authors get a boundary-oriented type map instead of a crate-name inventory. Application developers can convert RPC responses without JSON round trips and select the correct network representation. PeerDAS users can find the existing runnable flow and its node, fork, and KZG requirements.
1 parent 1dda229 commit df0a839

4 files changed

Lines changed: 173 additions & 2 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Protocol and RPC Types
3+
description: Choose Alloy primitives, consensus envelopes, EIP helpers, RPC responses, genesis, trie, and serialization types
4+
---
5+
6+
# Protocol and RPC types
7+
8+
Alloy models the same chain data at several boundaries. Choosing the type that belongs to the
9+
boundary avoids manual conversion and preserves network-specific fields.
10+
11+
| Boundary | Primary crates or modules | Examples |
12+
| --- | --- | --- |
13+
| Values and ABI | `alloy-primitives`, `alloy-sol-types`, `alloy-dyn-abi`, `alloy-json-abi` | address, `U256`, bytes, Solidity bindings |
14+
| Execution consensus | `alloy-consensus` | transaction envelopes, blocks, receipts, headers |
15+
| Protocol extensions | `alloy-eips` | block identifiers and implemented EIP data structures |
16+
| Network behavior | `alloy-network`, `alloy-network-primitives` | associated request, response, envelope, and receipt types |
17+
| JSON-RPC wire data | `alloy-rpc-types-*` | `TransactionRequest`, RPC block and receipt responses |
18+
| Chain configuration | `alloy-genesis` | execution genesis files and allocations |
19+
| State proofs | `alloy-trie` | trie roots, proofs, and prefix-sorted updates |
20+
| Representation helpers | `alloy-serde` | quantity, bytes, and compatibility serializers |
21+
22+
The `alloy` meta-crate re-exports enabled families as `alloy::primitives`, `alloy::consensus`,
23+
`alloy::eips`, `alloy::network`, and `alloy::rpc::types`.
24+
25+
## Primitives and ABI types
26+
27+
Use primitives for chain-independent values: `Address`, `B256`, `Bytes`, fixed bytes, signed and
28+
unsigned integers, hashes, and maps. The `sol!` macro and Solidity type traits provide static ABI
29+
encoding, event and error decoding, and EIP-712 definitions. Dynamic ABI and JSON ABI types are for
30+
interfaces discovered at runtime.
31+
32+
See [primitive types](/using-primitive-types/introduction), [`sol!`](/contract-interactions/using-sol!),
33+
and [static vs. dynamic ABI](/guides/static-dynamic-abi-in-alloy).
34+
35+
## Consensus types
36+
37+
Consensus types represent execution-layer objects independently of their JSON-RPC metadata:
38+
39+
- signed and unsigned transaction variants and EIP-2718 envelopes;
40+
- headers and blocks;
41+
- receipts, logs, withdrawals, and blob sidecars;
42+
- recovered transactions that pair an envelope with its signer.
43+
44+
Enable the `consensus` feature when using these through the meta-crate. Add `rlp`, `k256`, `kzg`, or
45+
`consensus-secp256k1` only when the operation needs that codec or cryptographic implementation.
46+
47+
Use consensus types for database storage, networking, hashing, roots, signing payloads, and
48+
protocol-level transformations. Use the network's RPC types at the provider boundary.
49+
50+
## RPC types wrap consensus data
51+
52+
Ethereum RPC responses embed consensus values and add fields supplied by the node. For example, an
53+
RPC transaction includes block placement metadata while containing a recovered consensus envelope;
54+
an RPC receipt includes transaction and block metadata around the consensus receipt.
55+
56+
Common conversion and access patterns include:
57+
58+
- `block.into_consensus()` to discard RPC-only metadata and obtain a consensus block;
59+
- `transaction.into_recovered()` for the recovered consensus transaction;
60+
- `.inner` or `.into_inner()` on wrapper types;
61+
- `map_*` and `try_map_*` methods when replacing an embedded header or transaction type.
62+
63+
See the runnable [consensus and RPC embedding example](/examples/providers/embed_consensus_rpc).
64+
Avoid re-serializing through JSON just to convert between these representations.
65+
66+
## Network-associated types
67+
68+
`Provider<N>` is generic over a `Network`. The network chooses the transaction type, envelope,
69+
receipt, header, request, and RPC response types used by provider methods. Ethereum is the default.
70+
71+
Use:
72+
73+
- `Ethereum` for Ethereum execution-layer responses;
74+
- a chain-specific implementation such as `op-alloy` for a supported ecosystem with extra
75+
transaction or receipt variants;
76+
- `AnyNetwork` when consuming heterogeneous responses and the catch-all representation is
77+
acceptable;
78+
- a custom `Network` implementation when a library owns a distinct typed protocol surface.
79+
80+
Choosing `Ethereum` for a chain with extra transaction variants can fail deserialization. See
81+
[interacting with multiple networks](/guides/interacting-with-multiple-networks) and the
82+
[`AnyNetwork` example](/examples/advanced/any_network).
83+
84+
## EIP modules
85+
86+
`alloy-eips` collects protocol structures and behavior that are shared across consensus, provider,
87+
and RPC crates. Support for a type does not imply that the connected chain has activated that EIP.
88+
Fork activation and RPC availability remain network and node concerns.
89+
90+
Examples include block identifiers and tags, typed envelope encodings, access lists,
91+
authorizations, blob sidecars, requests, and hardfork-related structures. Consult the
92+
[`alloy-eips` module list](https://docs.rs/alloy-eips/latest/alloy_eips/) for the exact release.
93+
94+
## Genesis and trie data
95+
96+
Use `alloy-genesis` for execution genesis configuration and account allocations. Genesis formats
97+
can contain client extensions, so preserve unknown or chain-specific fields when round-tripping a
98+
configuration.
99+
100+
Use `alloy-trie` for Merkle-Patricia Trie roots and proofs. Trie APIs generally require keys and
101+
updates in the documented order; incorrect ordering can produce a different root rather than a
102+
helpful RPC error. Treat proof verification input as untrusted data and validate the expected root.
103+
104+
These families are optional `genesis` and `trie` features on the meta-crate and are also available
105+
as direct dependencies for infrastructure libraries.
106+
107+
## Serialization
108+
109+
Ethereum JSON-RPC quantities, fixed bytes, byte strings, and nullability do not follow ordinary
110+
human-readable JSON conventions. Prefer the provided RPC and serde helper types over custom
111+
hex-string logic.
112+
113+
Enable `serde` for serde implementations and helpers. Compatibility formats such as
114+
`serde-bincode-compat` are opt-in; use the documented compatibility wrapper rather than assuming a
115+
type's normal serde representation is stable for non-self-describing storage.
116+
117+
For persistent data:
118+
119+
1. Choose whether the stored form is consensus, RPC-enriched, or application-specific.
120+
2. Version the schema independently of the Rust type name.
121+
3. Test round trips across dependency upgrades.
122+
4. Do not use debug output as a data format.
123+
124+
## Constrained and `no_std` users
125+
126+
The network-facing meta-crate primarily targets `std`. Some core and protocol crates support
127+
`no_std` with default features disabled. Depend on the narrow crate directly, inspect its own
128+
feature list, and compile the exact target. See [feature flags](/reference/feature-flags).

vocs/docs/pages/transactions/introduction.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Alloy supports building a transaction request for all types of transactions via
3030
- **EIP-2930 transactions:** Set the `access_list` field. This creates an access-list transaction.
3131
- **EIP-1559 transactions:** Set the `max_fee_per_gas` and `max_priority_fee_per_gas` fields. Omit the `gas_price` field.
3232
- **EIP-4844 transaction:** Use the `TransactionBuilder4844` to set blob specific fields using the `.with_blob_sidecar(..)` method.
33+
- **EIP-7594 sidecar:** Convert the pooled EIP-4844 sidecar to its PeerDAS cell-proof representation. This remains `TxType = 3`.
3334
- **EIP-7702 transaction:** Use the `TransactionBuilder7702` to set the authorization list using the `.with_authorization_list(..)` method.
3435

3536
### Legacy Transactions
@@ -75,7 +76,7 @@ Find the full example [here](/transactions/using-access-lists).
7576

7677
### EIP-1559 Transaction
7778

78-
By default the builder attempts to construct an [EIP1559](https://eips.ethereum.org/EIPS/eip-1559) transaction (`TxType = 2`). You can make this explicit by specifiying the priority gas fields.
79+
By default the builder attempts to construct an [EIP1559](https://eips.ethereum.org/EIPS/eip-1559) transaction (`TxType = 2`). You can make this explicit by specifying the priority gas fields.
7980

8081
```rust showLineNumbers
8182
use alloy::{
@@ -95,7 +96,7 @@ Find the full example [here](/transactions/sending-an-EIP-1559-transaction).
9596

9697
### EIP-4844 Transaction
9798

98-
EIP-4844 transactions (`TxType = 3`) are specific to Ethereum mainnet. One can build such transactions using the `TransactionBuilder4844` struct. This builder provides methods to set blob specific fields using the `.with_blob_sidecar(..)` method.
99+
EIP-4844 transactions (`TxType = 3`) are available on networks that have activated blob transactions. Build one using the `TransactionBuilder4844` trait, which provides `.with_blob_sidecar(..)` for blob-specific fields.
99100

100101
```rust showLineNumbers
101102
use alloy::{
@@ -114,6 +115,14 @@ let tx = TransactionRequest::default()
114115

115116
Find the full example [here](/transactions/sending-an-EIP-4844-transaction).
116117

118+
### EIP-7594 Blob Sidecar
119+
120+
EIP-7594 changes the pooled blob sidecar representation for PeerDAS; it does not introduce a new
121+
transaction type. Build and fill an EIP-4844 transaction, then convert its sidecar before encoding
122+
and submitting it to a compatible node.
123+
124+
Find the full example [here](/transactions/sending-an-EIP-7594-transaction).
125+
117126
### Example: EIP-7702 Transaction
118127

119128
EIP-7702 transaction (`TxType = 4`)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Sending an EIP-7594 Blob Sidecar
3+
description: Convert and send an EIP-4844 blob transaction with an EIP-7594 PeerDAS cell-proof sidecar
4+
---
5+
6+
# Sending an EIP-7594 blob sidecar
7+
8+
[EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) introduces PeerDAS cell proofs for blob data.
9+
It does not add a new execution-layer transaction type: the transaction remains an EIP-4844 blob
10+
transaction (`TxType = 3`), while its pooled sidecar uses the EIP-7594 representation.
11+
12+
The workflow is:
13+
14+
1. Build an EIP-4844 transaction and blob sidecar.
15+
2. Let the provider fill and sign the transaction.
16+
3. Convert the pooled EIP-4844 sidecar to `BlobTransactionSidecarEip7594` using the intended KZG
17+
settings.
18+
4. Encode the envelope and submit it with `send_raw_transaction`.
19+
20+
```rust
21+
// [!include ~/snippets/transactions/examples/send_eip7594_transaction.rs]
22+
```
23+
24+
The connected node must support the fork and pooled transaction format. The runnable example starts
25+
Anvil with the Osaka hardfork; it requires a recent compatible Anvil binary and the
26+
`provider-anvil-node` feature.
27+
28+
Use `EnvKzgSettings::Default` only when its environment-selected settings match the network. KZG
29+
setup and sidecar conversion errors should stop submission rather than falling back to a different
30+
format silently.
31+
32+
For ordinary pre-PeerDAS blob transactions, use the [EIP-4844 guide](/transactions/sending-an-EIP-4844-transaction).

vocs/sidebar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const sidebar: Sidebar = [
4949
{ text: 'Legacy Transaction', link: '/transactions/sending-a-legacy-transaction' },
5050
{ text: 'EIP-1559 Transaction', link: '/transactions/sending-an-EIP-1559-transaction' },
5151
{ text: 'EIP-4844 Transaction', link: '/transactions/sending-an-EIP-4844-transaction' },
52+
{ text: 'EIP-7594 Blob Sidecar', link: '/transactions/sending-an-EIP-7594-transaction' },
5253
{ text: 'EIP-7702 Transaction', link: '/transactions/sending-an-EIP-7702-transaction' },
5354
{ text: 'Using Access Lists', link: '/transactions/using-access-lists' },
5455
]
@@ -76,6 +77,7 @@ export const sidebar: Sidebar = [
7677
text: 'Reference',
7778
items: [
7879
{ text: 'Feature Flags', link: '/reference/feature-flags' },
80+
{ text: 'Protocol and RPC Types', link: '/reference/protocol-and-rpc-types' },
7981
]
8082
},
8183
{

0 commit comments

Comments
 (0)