|
1 | 1 | //! Example of how to transfer ERC20 tokens from one account to another using a signed permit.
|
2 | 2 |
|
3 |
| -use std::str::FromStr; |
4 |
| - |
5 | 3 | use alloy::{
|
6 | 4 | network::EthereumWallet,
|
7 | 5 | node_bindings::Anvil,
|
8 | 6 | primitives::{Address, U256},
|
9 | 7 | providers::{Provider, ProviderBuilder},
|
10 |
| - signers::{local::PrivateKeySigner, Signer}, |
| 8 | + signers::{ |
| 9 | + local::{ |
| 10 | + coins_bip39::{English, Mnemonic}, |
| 11 | + PrivateKeySigner, |
| 12 | + }, |
| 13 | + Signer, |
| 14 | + }, |
11 | 15 | sol,
|
12 | 16 | sol_types::eip712_domain,
|
13 | 17 | };
|
14 | 18 | use eyre::Result;
|
| 19 | +use std::str::FromStr; |
15 | 20 |
|
16 | 21 | // Codegen from artifact.
|
17 | 22 | sol!(
|
@@ -65,13 +70,10 @@ async fn main() -> Result<()> {
|
65 | 70 | // Ensure `anvil` is available in $PATH.
|
66 | 71 | let rpc_url = "https://reth-ethereum.ithaca.xyz/rpc";
|
67 | 72 | // NOTE: ⚠️ Due to changes in EIP-7702 (see: https://getfoundry.sh/anvil/overview/#eip-7702-and-default-accounts),
|
68 |
| - // the default mnemonic cannot be used for signature-based testing. |
69 |
| - // Instead, we use a custom mnemonic generated via: |
70 |
| - // `anvil --mnemonic-random 12 --fork-url $RPC_URL` |
71 |
| - let anvil = Anvil::new() |
72 |
| - .fork(rpc_url) |
73 |
| - .mnemonic("tunnel tiger ankle life lift risk wash material promote damp sadness middle") |
74 |
| - .try_spawn()?; |
| 73 | + // the default mnemonic cannot be used for signature-based testing. Instead, we use a custom |
| 74 | + // mnemonic. |
| 75 | + let mnemonic = generate_mnemonic()?; |
| 76 | + let anvil = Anvil::new().fork(rpc_url).mnemonic(mnemonic).try_spawn()?; |
75 | 77 |
|
76 | 78 | // Set up signers from the first two default Anvil accounts (Alice, Bob).
|
77 | 79 | let alice: PrivateKeySigner = anvil.keys()[8].clone().into();
|
@@ -146,3 +148,9 @@ async fn main() -> Result<()> {
|
146 | 148 |
|
147 | 149 | Ok(())
|
148 | 150 | }
|
| 151 | + |
| 152 | +fn generate_mnemonic() -> Result<String> { |
| 153 | + let mut rng = rand::thread_rng(); |
| 154 | + let mnemonic = Mnemonic::<English>::new_with_count(&mut rng, 12)?.to_phrase(); |
| 155 | + Ok(mnemonic) |
| 156 | +} |
0 commit comments