python环境:python3.11
python库:eth_account , eth_utils , mnemonic
注:纯本地运行因此保证了安全性,在开始前需要把用的库打上
Cmd输入 pip install mnemonic
import os from eth_account import Account from eth_utils import to_checksum_address from mnemonic import Mnemonic # 启用助记符功能 Account.enable_unaudited_hdwallet_features() # 生成所需的长度 entropy_bits = 128 entropy = os.urandom(entropy_bits // 8) # 根据熵生成助词 mnemonic = Mnemonic("english").to_mnemonic(entropy) # 从种子短语生成私钥 private_key = Account.from_mnemonic(mnemonic).key.hex() # 从私钥生成ETH钱包地址 address = to_checksum_address(Account.from_key(private_key).address) # 从私钥生成ETH公钥 account = Account.from_key(private_key) public_key = account._key_obj.public_key.to_hex() print("助记词:", mnemonic) print("私钥:", private_key) print("公钥:", public_key) print("钱包地址:", address)