Skip to content

Instantly share code, notes, and snippets.

@wilsoncusack
Last active December 29, 2021 18:30
Show Gist options
  • Save wilsoncusack/9a818806572170f973208b97c7cf9236 to your computer and use it in GitHub Desktop.
Save wilsoncusack/9a818806572170f973208b97c7cf9236 to your computer and use it in GitHub Desktop.
Rust Ethereum Vanity Address Generation
use ethers::{
signers::{LocalWallet, Signer},
};
fn main() {
let vanity_hex = "01";
// OR pass as input
// let mut args: Args = args();
// let vanity_hex = args.nth(1).unwrap();
let bytes_to_match = hex::decode(vanity_hex).expect("invalid hex");
let bytes_to_match_len = bytes_to_match.len();
let mut found = false;
while !found {
let wallet = LocalWallet::new(&mut rand::thread_rng());
let address = wallet.address();
let mut address_bytes = address.as_bytes().to_vec();
address_bytes.truncate(bytes_to_match_len);
if bytes_to_match == address_bytes {
println!("we did it!");
found = true;
println!("address: 0x{}", hex::encode(address.as_bytes()));
let signing_key = wallet.signer();
let signing_key_bytes = signing_key.to_bytes();
println!("private key: 0x{}", hex::encode(signing_key_bytes));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment