Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions examples/transactions/examples/send_eip7594_transaction.rs
Original file line number Diff line number Diff line change
@@ -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<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
let sidecar = sidecar.build_7594()?;
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now we can follow the existing 4844 example and do

 let sidecar = 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(sidecar);

provider.fill(tx).await.unwrap();

// and then convert the tx into the 7594 variant

this isnt super pretty but will do the job I believe


// 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(())
}