2026-01-06 00:05:03 +08:00
|
|
|
# generate_wallet.py
|
|
|
|
|
from eth_account import Account
|
2026-01-05 08:55:13 +08:00
|
|
|
|
2026-01-06 00:05:03 +08:00
|
|
|
def generate_evm_wallet(num_words: int = 12, passphrase: str = ""):
|
|
|
|
|
# HD 钱包能力需要显式开启(官方注明:实验性/未审计,未来可能变更)
|
|
|
|
|
Account.enable_unaudited_hdwallet_features()
|
2026-01-05 08:55:13 +08:00
|
|
|
|
2026-01-06 00:05:03 +08:00
|
|
|
acct, mnemonic = Account.create_with_mnemonic(
|
|
|
|
|
passphrase=passphrase,
|
|
|
|
|
num_words=num_words, # 12/15/18/21/24
|
|
|
|
|
account_path="m/44'/60'/0'/0/0", # EVM 常用路径
|
|
|
|
|
)
|
|
|
|
|
return mnemonic, acct.address, acct.key.hex()
|
2026-01-05 08:55:13 +08:00
|
|
|
|
2026-01-06 00:05:03 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
mnemonic, address, privkey = generate_evm_wallet(num_words=12)
|
|
|
|
|
print("mnemonic :", mnemonic)
|
|
|
|
|
print("address :", address)
|
|
|
|
|
print("privkey :", privkey)
|