-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from alloy-rs/send_4844
feat(transactions): send 4844 tx
- Loading branch information
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |