From 1155fec7d8913ed26675605bdbb848b40388d9ec Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 1 May 2024 13:40:19 -0700 Subject: [PATCH 1/3] feat(transactions): send 4844 --- Cargo.toml | 4 +- examples/transactions/examples/send_4844.rs | 41 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 examples/transactions/examples/send_4844.rs diff --git a/Cargo.toml b/Cargo.toml index f89995f7..70fcd1b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,9 @@ unnecessary_struct_initialization = "allow" use_self = "allow" [workspace.dependencies] -alloy = { git = "https://github.com/alloy-rs/alloy", rev = "7128c53", features = [ +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "d4e977e", features = [ + "consensus", + "kzg", "contract", "network", "node-bindings", diff --git a/examples/transactions/examples/send_4844.rs b/examples/transactions/examples/send_4844.rs new file mode 100644 index 00000000..d332fc06 --- /dev/null +++ b/examples/transactions/examples/send_4844.rs @@ -0,0 +1,41 @@ +//! Example showing how to send a 4844 tx. + +use alloy::{ + consensus::{SidecarBuilder, SimpleCoder}, + network::TransactionBuilder, + node_bindings::Anvil, + providers::{Provider, ProviderBuilder}, + rpc::types::eth::TransactionRequest, +}; +use eyre::Result; + +#[tokio::main] +async fn main() -> Result<()> { + let anvil = Anvil::new().args(["--hardfork", "cancun"]).spawn(); + let provider = ProviderBuilder::new().on_builtin(&anvil.endpoint()).await?; + + let from = anvil.addresses()[0]; + let to = anvil.addresses()[1]; + + let sidecar: SidecarBuilder<SimpleCoder> = + SidecarBuilder::from_slice("Blobs are fun!".as_bytes()); + + let sidecar = sidecar.build()?; + + let gas_price = provider.get_gas_price().await?; + let eip1559_est = provider.estimate_eip1559_fees(None).await?; + let tx = TransactionRequest::default() + .with_from(from) + .with_to(to) + .with_nonce(0) + .with_max_fee_per_blob_gas(gas_price) + .with_max_fee_per_gas(eip1559_est.max_fee_per_gas) + .with_max_priority_fee_per_gas(eip1559_est.max_priority_fee_per_gas) + .with_blob_sidecar(sidecar); + + let receipt = provider.send_transaction(tx).await?.get_receipt().await?; + + assert!(receipt.blob_gas_used.unwrap() > 0); + + Ok(()) +} From f25d16c1b44a8fa8eb6cc55269f4c9f529d2418a Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 1 May 2024 13:47:00 -0700 Subject: [PATCH 2/3] bump alloy and nits --- Cargo.toml | 2 +- examples/transactions/examples/gas_price_usd.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70fcd1b1..f25c65e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ unnecessary_struct_initialization = "allow" use_self = "allow" [workspace.dependencies] -alloy = { git = "https://github.com/alloy-rs/alloy", rev = "d4e977e", features = [ +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "32f58e2", features = [ "consensus", "kzg", "contract", diff --git a/examples/transactions/examples/gas_price_usd.rs b/examples/transactions/examples/gas_price_usd.rs index 212db3ba..f97a7606 100644 --- a/examples/transactions/examples/gas_price_usd.rs +++ b/examples/transactions/examples/gas_price_usd.rs @@ -5,7 +5,7 @@ use alloy::{ node_bindings::Anvil, primitives::{address, utils::format_units, Address, Bytes, U256}, providers::{Provider, ProviderBuilder}, - rpc::types::eth::{BlockId, TransactionRequest}, + rpc::types::eth::TransactionRequest, sol, sol_types::SolCall, }; @@ -40,7 +40,7 @@ async fn main() -> Result<()> { // Call the Chainlink ETH/USD feed contract. let tx = TransactionRequest::default().with_to(ETH_USD_FEED).with_input(input); - let response = provider.call(&tx, BlockId::latest()).await?; + let response = provider.call(&tx).await?; let result = U256::from_str(&response.to_string())?; // Get the gas price of the network. From 0f8998271ac7a14bdcfee2278907638d123cba22 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 3 May 2024 15:33:45 -0700 Subject: [PATCH 3/3] bump alloy and complete send_4844 eg --- Cargo.toml | 3 ++- README.md | 5 +++-- examples/transactions/examples/gas_price_usd.rs | 2 +- examples/transactions/examples/send_4844.rs | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ad60ddb..faf11d45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,9 +81,10 @@ unnecessary_struct_initialization = "allow" use_self = "allow" [workspace.dependencies] -alloy = { git = "https://github.com/alloy-rs/alloy", rev = "2d1c40c", features = [ +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "e22d9be", features = [ "consensus", "kzg", + "eips", "contract", "network", "node-bindings", diff --git a/README.md b/README.md index 058e4c89..1b9403fa 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,9 @@ This repository contains the following examples: - [x] [Trace transaction](./examples/transactions/examples/trace_transaction.rs) - [x] [Transfer ERC20 token](./examples/transactions/examples/transfer_erc20.rs) - [x] [Transfer ETH](./examples/transactions/examples/transfer_eth.rs) - - [x] [Sign and send a raw transaction](./examples/transactions/examples/sign_transaction.rs) - - [x] [Send transaction with access list](./examples/transactions/examples/with_access_list.rs) + - [x] [Sign and send a raw transaction](./examples/transactions/examples/sign_transaction.rs) + - [x] [Send transaction with access list](./examples/transactions/examples/with_access_list.rs) + - [x] [Send 4844 transaction](./examples/transactions/examples/send_4844.rs) - [x] Wallets - [x] [AWS signer](./examples/wallets/examples/aws_signer.rs) - [x] [Ledger signer](./examples/wallets/examples/ledger_signer.rs) diff --git a/examples/transactions/examples/gas_price_usd.rs b/examples/transactions/examples/gas_price_usd.rs index e0db77d4..e4435691 100644 --- a/examples/transactions/examples/gas_price_usd.rs +++ b/examples/transactions/examples/gas_price_usd.rs @@ -5,7 +5,7 @@ use alloy::{ node_bindings::Anvil, primitives::{address, utils::format_units, Address, Bytes, U256}, providers::{Provider, ProviderBuilder}, - rpc::types::eth::TransactionRequest, + rpc::types::eth::{BlockId, TransactionRequest}, sol, sol_types::SolCall, }; diff --git a/examples/transactions/examples/send_4844.rs b/examples/transactions/examples/send_4844.rs index d332fc06..80f08c24 100644 --- a/examples/transactions/examples/send_4844.rs +++ b/examples/transactions/examples/send_4844.rs @@ -2,6 +2,7 @@ use alloy::{ consensus::{SidecarBuilder, SimpleCoder}, + eips::eip4844::DATA_GAS_PER_BLOB, network::TransactionBuilder, node_bindings::Anvil, providers::{Provider, ProviderBuilder}, @@ -35,7 +36,7 @@ async fn main() -> Result<()> { let receipt = provider.send_transaction(tx).await?.get_receipt().await?; - assert!(receipt.blob_gas_used.unwrap() > 0); + assert_eq!(receipt.blob_gas_used.unwrap(), DATA_GAS_PER_BLOB as u128); Ok(()) }