【问题标题】:Access private key after personal.newAccount in web3.py在 web3.py 中的 personal.newAccount 之后访问私钥
【发布时间】:2018-12-01 21:07:40
【问题描述】:

我在 python 3.6 中使用web3.py 创建了一个以太坊帐户:

web3.personal.newAccount('password')

如何访问该帐户的私钥?

【问题讨论】:

    标签: python python-3.x ethereum web3


    【解决方案1】:

    当您在节点上创建帐户时(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/…
    猜你喜欢
    • 2021-06-29
    • 2022-11-16
    • 2018-11-18
    • 2021-08-16
    • 2022-07-14
    • 2020-10-26
    • 2021-12-16
    • 2011-05-02
    • 2018-12-01
    相关资源
    最近更新 更多