Sitelet https://github.com/SharkHand3/examples/commit/ecb45d06575129f0210f443887f391cd28db66aa
Skip to content

Commit ecb45d0

Browse files
authored
chore(transactions) use send_tx_envelope rather than manually encoding and calling send_raw_transaction (alloy-rs#101)
* use send_tx_envelope as a convenience method when using send_raw_transaction * spelling
1 parent 24b72b7 commit ecb45d0

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎examples/transactions/examples/send_raw_transaction.rs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example of signing, encoding and sending a raw transaction using a wallet.
22
33
use alloy::{
4-
network::{eip2718::Encodable2718, EthereumSigner, TransactionBuilder},
4+
network::{EthereumSigner, TransactionBuilder},
55
node_bindings::Anvil,
66
primitives::U256,
77
providers::{Provider, ProviderBuilder},
@@ -39,14 +39,13 @@ async fn main() -> Result<()> {
3939
.with_max_priority_fee_per_gas(1_000_000_000)
4040
.with_max_fee_per_gas(20_000_000_000);
4141

42-
// Build the transaction using the `EthereumSigner` with the provided signer.
42+
// Build and sign the transaction using the `EthereumSigner` with the provided signer.
4343
let tx_envelope = tx.build(&signer).await?;
4444

45-
// Encode the transaction using EIP-2718 encoding.
46-
let tx_encoded = tx_envelope.encoded_2718();
47-
4845
// Send the raw transaction and retrieve the transaction receipt.
49-
let receipt = provider.send_raw_transaction(&tx_encoded).await?.get_receipt().await?;
46+
// [Provider::send_tx_envelope] is a convenience method that encodes the transaction using
47+
// EIP-2718 encoding and broadcasts it to the network using [Provider::send_raw_transaction].
48+
let receipt = provider.send_tx_envelope(tx_envelope).await?.get_receipt().await?;
5049

5150
println!("Sent transaction: {}", receipt.transaction_hash);
5251

0 commit comments

Comments
 (0)