Sitelet https://github.com/alloy-rs/examples/commit/79ac943b55a59a8fcacca2ef99942fbcf5e3bbbf
Skip to content

Commit 79ac943

Browse files
authored
only set .with_from field if required (#104)
1 parent ecb45d0 commit 79ac943

19 files changed

Lines changed: 55 additions & 103 deletions

‎examples/fillers/examples/gas_filler.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ async fn main() -> Result<()> {
1919
// Set up signer from the first default Anvil account (Alice).
2020
let signer: LocalWallet = anvil.keys()[0].clone().into();
2121

22-
// Create two users, Alice and Vitalik.
23-
let alice = signer.address();
24-
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
25-
2622
// Create a provider with the signer.
2723
let rpc_url = anvil.endpoint().parse()?;
2824
let provider = ProviderBuilder::new()
@@ -33,9 +29,9 @@ async fn main() -> Result<()> {
3329
.signer(EthereumSigner::from(signer))
3430
.on_http(rpc_url);
3531

36-
// Create an EIP-1559 type transaction.
32+
// Build an EIP-1559 type transaction to send 100 wei to Vitalik.
33+
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
3734
let tx = TransactionRequest::default()
38-
.with_from(alice)
3935
.with_to(vitalik)
4036
.with_value(U256::from(100))
4137
// Notice that without the `NonceFiller`, you need to set `nonce` field.

‎examples/fillers/examples/nonce_filler.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ async fn main() -> Result<()> {
2828
// Set up signer from the first default Anvil account (Alice).
2929
let signer: LocalWallet = anvil.keys()[0].clone().into();
3030

31-
// Create two users, Alice and Vitalik.
32-
let alice = signer.address();
33-
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
34-
3531
// Create a provider with the signer.
3632
let rpc_url = anvil.endpoint().parse()?;
3733
let provider = ProviderBuilder::new()
@@ -42,9 +38,9 @@ async fn main() -> Result<()> {
4238
.signer(EthereumSigner::from(signer))
4339
.on_http(rpc_url);
4440

45-
// Create an EIP-1559 type transaction.
41+
// Build an EIP-1559 type transaction to send 100 wei to Vitalik.
42+
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
4643
let tx = TransactionRequest::default()
47-
.with_from(alice)
4844
.with_to(vitalik)
4945
.with_value(U256::from(100))
5046
// Notice that without the `GasFiller`, you need to set the gas related fields.

‎examples/fillers/examples/recommended_fillers.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ async fn main() -> Result<()> {
1919
// Set up signer from the first default Anvil account (Alice).
2020
let signer: LocalWallet = anvil.keys()[0].clone().into();
2121

22-
// Create two users, Alice and Vitalik.
23-
let alice = signer.address();
24-
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
25-
2622
// Create a provider with the signer.
2723
let rpc_url = anvil.endpoint().parse()?;
2824
let provider = ProviderBuilder::new()
@@ -31,12 +27,12 @@ async fn main() -> Result<()> {
3127
.signer(EthereumSigner::from(signer))
3228
.on_http(rpc_url);
3329

34-
// Build a EIP-1559 type transaction.
30+
// Build an EIP-1559 type transaction to send 100 wei to Vitalik.
3531
// Notice that the `nonce` field is set by the `NonceFiller`.
3632
// Notice that the gas related fields are set by the `GasFiller`.
3733
// Notice that the `chain_id` field is set by the `ChainIdFiller`.
38-
let tx =
39-
TransactionRequest::default().with_from(alice).with_to(vitalik).with_value(U256::from(100));
34+
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
35+
let tx = TransactionRequest::default().with_to(vitalik).with_value(U256::from(100));
4036

4137
// Send the transaction, the nonce (0) is automatically managed by the provider.
4238
let builder = provider.send_transaction(tx.clone()).await?;

‎examples/fillers/examples/signer_filler.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ async fn main() -> Result<()> {
1919
// Set up signer from the first default Anvil account (Alice).
2020
let signer: LocalWallet = anvil.keys()[0].clone().into();
2121

22-
// Create two users, Alice and Vitalik.
23-
let alice = signer.address();
24-
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
25-
2622
// Create a provider with the signer.
2723
let rpc_url = anvil.endpoint().parse()?;
2824
let provider = ProviderBuilder::new()
@@ -31,12 +27,12 @@ async fn main() -> Result<()> {
3127
.on_http(rpc_url);
3228

3329
// Build a legacy type transaction to send 100 wei to Vitalik.
30+
let vitalik = address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
3431
let tx = TransactionRequest::default()
35-
.with_from(alice)
36-
// Notice that without the `NonceFiller`, you need to manually set the nonce field.
37-
.with_nonce(0)
3832
.with_to(vitalik)
3933
.with_value(U256::from(100))
34+
// Notice that without the `NonceFiller`, you need to manually set the nonce field.
35+
.with_nonce(0)
4036
// Notice that without the `GasFiller`, you need to set the gas related fields.
4137
.with_gas_price(20_000_000_000)
4238
.with_gas_limit(21_000);

‎examples/providers/examples/builder.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ async fn main() -> Result<()> {
3131
.on_http(rpc_url);
3232

3333
// Create a transaction.
34-
let tx =
35-
TransactionRequest::default().with_from(alice).with_to(bob).with_value(U256::from(100));
34+
let tx = TransactionRequest::default().with_to(bob).with_value(U256::from(100));
3635

3736
// Send the transaction and wait for the broadcast.
3837
let pending_tx = provider.send_transaction(tx).await?;

‎examples/transactions/examples/send_eip1559_transaction.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ async fn main() -> Result<()> {
2424
let bob = anvil.addresses()[1];
2525

2626
// Build a transaction to send 100 wei from Alice to Bob.
27+
// The `from` field is automatically filled to the first signer's address (Alice).
2728
let tx = TransactionRequest::default()
28-
.with_from(alice)
2929
.with_to(bob)
3030
.with_nonce(0)
3131
.with_chain_id(anvil.chain_id())

‎examples/transactions/examples/send_eip4844_transaction.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ async fn main() -> Result<()> {
2929
let sidecar = sidecar.build()?;
3030

3131
// Build a transaction to send the sidecar from Alice to Bob.
32+
// The `from` field is automatically filled to the first signer's address (Alice).
3233
let gas_price = provider.get_gas_price().await?;
3334
let eip1559_est = provider.estimate_eip1559_fees(None).await?;
3435
let tx = TransactionRequest::default()
35-
.with_from(alice)
3636
.with_to(bob)
3737
.with_nonce(0)
3838
.with_max_fee_per_blob_gas(gas_price)

‎examples/transactions/examples/send_legacy_transaction.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ async fn main() -> Result<()> {
2424
let bob = anvil.addresses()[1];
2525

2626
// Build a transaction to send 100 wei from Alice to Bob.
27+
// The `from` field is automatically filled to the first signer's address (Alice).
2728
let tx = TransactionRequest::default()
28-
.with_from(alice)
2929
.with_to(bob)
3030
.with_nonce(0)
3131
.with_value(U256::from(100))

‎examples/transactions/examples/send_private_transaction.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ async fn main() -> Result<()> {
3838
// Create a signer from a random wallet.
3939
let signer = LocalWallet::random();
4040

41-
// Create two users, Alice and Bob.
42-
let alice = signer.address();
43-
let bob = LocalWallet::random().address();
44-
4541
// Build a transaction to send 100 wei from Alice to Bob.
42+
// The `from` field is automatically filled to the first signer's address (Alice).
43+
let bob = LocalWallet::random().address();
4644
let tx = TransactionRequest::default()
47-
.with_from(alice)
4845
.with_to(bob)
4946
.with_nonce(0)
5047
.with_chain_id(1)

‎examples/transactions/examples/send_raw_transaction.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ async fn main() -> Result<()> {
2929
let bob = anvil.addresses()[1];
3030

3131
// Build a transaction to send 100 wei from Alice to Bob.
32+
// The `from` field is automatically filled to the first signer's address (Alice).
3233
let tx = TransactionRequest::default()
33-
.with_from(alice)
3434
.with_to(bob)
3535
.with_nonce(0)
3636
.with_chain_id(anvil.chain_id())

0 commit comments

Comments
 (0)