forked from alloy-rs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmnemonic_signer.rs
More file actions
34 lines (27 loc) · 1.11 KB
/
Copy pathmnemonic_signer.rs
File metadata and controls
34 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Example of using `MnemonicBuilder` to access a wallet from a mnemonic phrase.
use alloy::signers::local::{coins_bip39::English, MnemonicBuilder};
use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
let phrase = "work man father plunge mystery proud hollow address reunion sauce theory bonus";
let index = 0u32;
let password = "TREZOR123";
// Access mnemonic phrase with password.
// Child key at derivation path: m/44'/60'/0'/0/{index}.
let wallet = MnemonicBuilder::<English>::default()
.phrase(phrase)
.index(index)?
// Use this if your mnemonic is encrypted.
.password(password)
.build()?;
println!("Wallet: {}", wallet.address());
// Generate a random wallet (24 word phrase) at custom derivation path.
let wallet = MnemonicBuilder::<English>::default()
.word_count(24)
.derivation_path("m/44'/60'/0'/2/1")?
// Optionally add this if you want the generated mnemonic to be written
// to a file `.write_to(path)`.
.build_random()?;
println!("Random wallet: {}", wallet.address());
Ok(())
}