Safety Guest'T blog

  • 首页
  • 归档
  • 软件开发
  • 网络安全
  • 逆向破解
  • 人工智能
  • 资源分享
  • 区 块 链
  • 隐私政策
  • 友情链接

区块链-Python生成ETH钱包

  • Tz
  • 2023-07-14
  • 0

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)
    
    
 
© 2025 Safety Guest'T blog
Theme by Wing
渝ICP备 2021011909号 渝公网安备 50019002502382号
  • {{ item.name }}
  • {{ item.name }}