Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transactions): send 4844 tx #69

Merged
merged 4 commits into from
May 4, 2024
Merged
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +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",
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions examples/transactions/examples/send_4844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Example showing how to send a 4844 tx.

use alloy::{
consensus::{SidecarBuilder, SimpleCoder},
eips::eip4844::DATA_GAS_PER_BLOB,
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_eq!(receipt.blob_gas_used.unwrap(), DATA_GAS_PER_BLOB as u128);

Ok(())
}
Loading