pip install web3.py
安装web3.py是会自动安装 eth-account
使用web3的方式
from web3 import Web3
if __name__ == '__main__':
w3 = Web3()
acct = w3.eth.account.create()
print(acct.address)
直接使用 eth_account,效果与 web3 一致
from eth_account import Account
if __name__ == '__main__':
acct = Account.create()
print(acct.address)
# 账户的私钥
print(acct.key.hex())
from eth_account import Account
import json
acct = Account.create()
with open('wallet/' + acct.address + '.keystore', 'w') as f:
f.write(json.dumps(acct.encrypt('password')))
from eth_account import Account
import json
if __name__ == '__main__':
key = '...'
acct = Account.from_key(key)
#导出 json 文件
encrypted = acct.encrypt('123456')
with open('my-key.json','w') as f:
f.write(json.dumps(encrypted))
from eth_account import Account
if __name__ == '__main__':
encrypted = '...'
private_key = Account.decrypt(encrypted, 'password')