From d47204ea883d63b69d366d21dc533037d20c7feb Mon Sep 17 00:00:00 2001 From: frankudoags Date: Sat, 18 Oct 2025 10:07:51 +0100 Subject: [PATCH] feat(examples): - add example for sending EIP-7594 transaction - bump alloy to 1.0.41 --- Cargo.toml | 2 +- .../examples/send_eip7594_transaction.rs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/transactions/examples/send_eip7594_transaction.rs diff --git a/Cargo.toml b/Cargo.toml index a72266e..1787f0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ significant_drop_tightening = "allow" needless_return = "allow" [workspace.dependencies] -alloy = { version = "1.0.38", features = [ +alloy = { version = "1.0.41", features = [ "eips", "full", "json-rpc", diff --git a/examples/transactions/examples/send_eip7594_transaction.rs b/examples/transactions/examples/send_eip7594_transaction.rs new file mode 100644 index 0000000..fe61efc --- /dev/null +++ b/examples/transactions/examples/send_eip7594_transaction.rs @@ -0,0 +1,46 @@ +//! Example showing how to send an [EIP-7594](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7594.md) transaction. + +use alloy::{ + consensus::{SidecarBuilder, SimpleCoder}, + 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", "cancun"]))?; + + // 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. + let sidecar: SidecarBuilder = SidecarBuilder::from_slice(b"Blobs are fun!"); + let sidecar = sidecar.build_7594()?; + + // TODO: Build a transaction to send the sidecar from Alice to Bob. I'm not sure how to create this tx atm, researching... + + // Send the transaction and wait for the broadcast. + let pending_tx = provider.send_raw_transaction(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(()) +}