Sending an EIP-7594 blob sidecar
EIP-7594 introduces PeerDAS cell proofs for blob data.
It does not add a new execution-layer transaction type: the transaction remains an EIP-4844 blob
transaction (TxType = 3), while its pooled sidecar uses the EIP-7594 representation.
The workflow is:
- Build an EIP-4844 transaction and blob sidecar.
- Let the provider fill and sign the transaction.
- Convert the pooled EIP-4844 sidecar to
BlobTransactionSidecarEip7594using the intended KZG settings. - Encode the envelope and submit it with
send_raw_transaction.
//! Example showing how to send an [EIP-7594](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7594.md) transaction.
use alloy::{
consensus::{
BlobTransactionSidecarVariant, EthereumTxEnvelope, SidecarBuilder, SimpleCoder,
TxEip4844WithSidecar,
},
eips::{eip7594::BlobTransactionSidecarEip7594, Encodable2718},
network::{TransactionBuilder, TransactionBuilder4844},
providers::{Provider, ProviderBuilder},
rpc::types::TransactionRequest,
};
use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node with the Cancun hardfork enabled.
// Ensure `anvil` is available in $PATH.
let provider = ProviderBuilder::new()
.connect_anvil_with_wallet_and_config(|anvil| anvil.args(["--hardfork", "osaka"]))?;
// Create two users, Alice and Bob.
let accounts = provider.get_accounts().await?;
let alice = accounts[0];
let bob = accounts[1];
// Create a sidecar with some data and build it directly as an EIP-7594 sidecar.
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
let sidecar: BlobTransactionSidecarEip7594 = sidecar.build()?;
// Build a transaction to send the sidecar from Alice to Bob.
// The `from` field is automatically filled to the first signer's address (Alice).
let tx = TransactionRequest::default()
.with_to(bob)
.with_blob_sidecar(BlobTransactionSidecarVariant::Eip7594(sidecar));
// Fill the transaction (e.g., nonce, gas, etc.) using the provider and convert it to an
// envelope.
let envelope = provider.fill(tx).await?.try_into_envelope()?;
// Convert the envelope into a pooled transaction with EIP-7594 sidecar.
let tx: EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarEip7594>> = envelope
.try_into_pooled()?
.try_map_eip4844(|tx| tx.try_map_sidecar(|sidecar| sidecar.try_into_eip7594()))?;
let encoded_tx = tx.encoded_2718();
// Send the raw transaction to the network.
let pending_tx = provider.send_raw_transaction(&encoded_tx).await?;
println!("Pending transaction... {}", pending_tx.tx_hash());
// Wait for the transaction to be included and get the receipt.
let receipt = pending_tx.get_receipt().await?;
println!(
"Transaction included in block {}",
receipt.block_number.expect("Failed to get block number")
);
assert_eq!(receipt.from, alice);
assert_eq!(receipt.to, Some(bob));
Ok(())
}The connected node must support the fork and pooled transaction format. The runnable example starts
Anvil with the Osaka hardfork; it requires a recent compatible Anvil binary and the
provider-anvil-node feature.
Use EnvKzgSettings::Default only when its environment-selected settings match the network. KZG
setup and sidecar conversion errors should stop submission rather than falling back to a different
format silently.
For ordinary pre-PeerDAS blob transactions, use the EIP-4844 guide.
