Auto generate wallet addresses and their private keys


Thu Mar 24 2022 11:21:14 GMT+0000 (UTC)

Saved by @Taylor #python #web3

# web3 library that contains functions to generate Ethereum accounts and sign transactions and data
#Importing Account from the eth_account module of
from eth_account import Account
# python module used for generating random numbers
import secrets

#Generating a random hexadecimal string of 32 bytes / 64 characters and storing it in priv variable
priv = secrets.token_hex(32)

#Attaching 0x prefix to our 64 character hexadecimal string stored in priv and storing the new string in variable private_key
private_key = "0x" + priv
print("SAVE BUT DO NOT SHARE:", private_key)

#Creating a new account using the private_key and storing it in variable acct
acct = Account.from_key(private_key)
print("Address:", acct.address)