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

Commit 31f21b2

Browse files
authored
minor fixes to examples (alloy-rs#67)
1 parent 89f90ed commit 31f21b2

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ This repository contains the following examples:
6161
- [x] [Transfer ERC20 token](./examples/transactions/examples/transfer_erc20.rs)
6262
- [x] [Transfer ETH](./examples/transactions/examples/transfer_eth.rs)
6363
- [x] [Sign and send a raw transaction](./examples/transactions/examples/sign_transaction.rs)
64+
- [x] [Send transaction with access list](./examples/transactions/examples/with_access_list.rs)
6465
- [ ] Wallets
65-
- [ ] AWS signer
66+
- [x] [AWS signer](./examples/wallets/examples/aws_signer.rs)
6667
- [ ] GCP signer
6768
- [x] [Ledger signer](./examples/wallets/examples/ledger_signer.rs)
6869
- [x] [Private key signer](./examples/wallets/examples/private_key_signer.rs)

‎examples/transactions/examples/with_access_list.rs‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Example of sending a EIP-1559 transaction with access list.
2+
23
use alloy::{
34
node_bindings::Anvil,
45
providers::{Provider, ProviderBuilder},
@@ -7,6 +8,7 @@ use alloy::{
78
};
89
use eyre::Result;
910

11+
// Codegen from artifact.
1012
sol!(
1113
#[allow(missing_docs)]
1214
#[sol(rpc)]
@@ -16,44 +18,49 @@ sol!(
1618

1719
#[tokio::main]
1820
async fn main() -> Result<()> {
19-
// Spin up anvil node.
20-
21+
// Spin up a forked Anvil node.
22+
// Ensure `anvil` is available in $PATH.
2123
let anvil = Anvil::new().try_spawn()?;
2224

2325
// Create a provider.
2426
let provider =
2527
ProviderBuilder::new().with_recommended_fillers().on_builtin(&anvil.endpoint()).await?;
2628

29+
// Create two users, Alice and Bob.
2730
let alice = anvil.addresses()[0];
2831
let bob = anvil.addresses()[1];
2932

30-
let contract_addr = SimpleStorage::deploy_builder(provider.clone(), "foo".to_string())
33+
// Deploy the `SimpleStorage` contract.
34+
let contract_address = SimpleStorage::deploy_builder(provider.clone(), "initial".to_string())
3135
.from(alice)
3236
.deploy()
3337
.await?;
38+
let contract = SimpleStorage::new(contract_address, provider.clone());
3439

35-
let contract = SimpleStorage::new(contract_addr, provider.clone());
36-
40+
// Build a transaction to set the values.
3741
let set_value_call = contract.setValues("hello".to_string(), "world".to_string());
3842
let calldata = set_value_call.calldata().to_owned();
3943

4044
let eip1559_fees = provider.estimate_eip1559_fees(None).await?;
4145
let tx = TransactionRequest::default()
4246
.from(bob)
43-
.to(contract_addr)
47+
.to(contract_address)
4448
.input(calldata.into())
4549
.max_fee_per_gas(eip1559_fees.max_fee_per_gas)
4650
.max_priority_fee_per_gas(eip1559_fees.max_priority_fee_per_gas);
4751

52+
// Create an access list for the transaction.
4853
let access_list_with_gas_used = provider.create_access_list(&tx, BlockId::latest()).await?;
4954

50-
let tx_with_access_list = tx.clone().access_list(access_list_with_gas_used.access_list);
55+
// Add the access list to the transaction.
56+
let tx_with_access_list = tx.access_list(access_list_with_gas_used.access_list);
5157

52-
let pending_tx = provider.send_transaction(tx_with_access_list).await?;
53-
54-
let _receipt = pending_tx.get_receipt().await?;
58+
// Send the transaction with the access list.
59+
provider.send_transaction(tx_with_access_list).await?.get_receipt().await?;
5560

61+
// Check the value of the contract.
5662
let value = contract.getValue().call().await?;
63+
5764
assert_eq!(value._0, "hello".to_string());
5865

5966
Ok(())
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Example showing how to use the AWS KMS signer.
2+
23
use alloy::signers::{aws::AwsSigner, Signer};
34
use aws_config::BehaviorVersion;
45
use eyre::Result;
@@ -8,15 +9,15 @@ async fn main() -> Result<()> {
89
let Ok(key_id) = std::env::var("AWS_KEY_ID") else {
910
return Ok(());
1011
};
12+
1113
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
1214
let client = aws_sdk_kms::Client::new(&config);
13-
14-
let signer = AwsSigner::new(client, key_id, Some(1)).await.unwrap();
15+
let signer = AwsSigner::new(client, key_id, Some(1)).await?;
1516

1617
let message = "Hello, world!";
18+
let signature = signer.sign_message(message.as_bytes()).await.unwrap();
1719

18-
let sig = signer.sign_message(message.as_bytes()).await.unwrap();
19-
assert_eq!(sig.recover_address_from_msg(message).unwrap(), signer.address());
20+
assert_eq!(signature.recover_address_from_msg(message)?, signer.address());
2021

2122
Ok(())
2223
}

0 commit comments

Comments
 (0)