Skip to content
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ serde_json = "1.0"
# benchmarking
criterion = "0.5"
ethers = "2.0.14"

# rand
rand = "0.8.5"
1 change: 1 addition & 0 deletions examples/transactions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ workspace = true
alloy = { workspace = true, features = ["eip712"]}

eyre.workspace = true
rand.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
28 changes: 18 additions & 10 deletions examples/transactions/examples/permit2_signature_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
//! Example of how to transfer ERC20 tokens from one account to another using a signed permit.

use std::str::FromStr;

use alloy::{
network::EthereumWallet,
node_bindings::Anvil,
primitives::{Address, U256},
providers::{Provider, ProviderBuilder},
signers::{local::PrivateKeySigner, Signer},
signers::{
local::{
coins_bip39::{English, Mnemonic},
PrivateKeySigner,
},
Signer,
},
sol,
sol_types::eip712_domain,
};
use eyre::Result;
use std::str::FromStr;

// Codegen from artifact.
sol!(
Expand Down Expand Up @@ -65,13 +70,10 @@ async fn main() -> Result<()> {
// Ensure `anvil` is available in $PATH.
let rpc_url = "https://reth-ethereum.ithaca.xyz/rpc";
// NOTE: ⚠️ Due to changes in EIP-7702 (see: https://getfoundry.sh/anvil/overview/#eip-7702-and-default-accounts),
// the default mnemonic cannot be used for signature-based testing.
// Instead, we use a custom mnemonic generated via:
// `anvil --mnemonic-random 12 --fork-url $RPC_URL`
let anvil = Anvil::new()
.fork(rpc_url)
.mnemonic("tunnel tiger ankle life lift risk wash material promote damp sadness middle")
.try_spawn()?;
// the default mnemonic cannot be used for signature-based testing. Instead, we use a custom
// mnemonic.
let mnemonic = generate_mnemonic()?;
let anvil = Anvil::new().fork(rpc_url).mnemonic(mnemonic).try_spawn()?;

// Set up signers from the first two default Anvil accounts (Alice, Bob).
let alice: PrivateKeySigner = anvil.keys()[8].clone().into();
Expand Down Expand Up @@ -146,3 +148,9 @@ async fn main() -> Result<()> {

Ok(())
}

fn generate_mnemonic() -> Result<String> {
let mut rng = rand::thread_rng();
let mnemonic = Mnemonic::<English>::new_with_count(&mut rng, 12)?.to_phrase();
Ok(mnemonic)
}
2 changes: 1 addition & 1 deletion examples/wallets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gcloud-sdk = { version = "0.27", features = [
"google-cloud-kms-v1",
"google-longrunning",
] }
rand = "0.8.5"
rand.workspace = true
serde = { workspace = true, features = ["derive"] }
tempfile = "3.19"
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }