【发布时间】:2018-12-01 21:07:40
【问题描述】:
我在 python 3.6 中使用web3.py 创建了一个以太坊帐户:
web3.personal.newAccount('password')
如何访问该帐户的私钥?
【问题讨论】:
标签: python python-3.x ethereum web3
我在 python 3.6 中使用web3.py 创建了一个以太坊帐户:
web3.personal.newAccount('password')
如何访问该帐户的私钥?
【问题讨论】:
标签: python python-3.x ethereum web3
当您在节点上创建帐户时(w3.personal.newAccount() 会这样做),节点 hosts the private key;不打算直接访问它。
如果您必须具有对私钥的本地访问权限,您可以:
如果节点是geth,则提取密钥如下所示:
with open('~/.ethereum/keystore/UTC--...4909639D2D17A3F753ce7d93fa0b9aB12E') as keyfile:
encrypted_key = keyfile.read()
private_key = w3.eth.account.decrypt(encrypted_key, 'correcthorsebatterystaple')
安全提示——不要将密钥或密码保存在任何地方,尤其是共享源文件中
【讨论】:
web3.eth.account.create(extra_entropy) 时,它不会在我的节点中创建新帐户
w3.eth.account.encrypt() 生成大多数节点可以导入的 geth 样式的密钥文件。有关参数和示例,请参阅eth-account.readthedocs.io/en/latest/…。