繁体   English   中英

如何使用 python 创建比特币地址

[英]How to create bitcoin address with python

我正在创建一个应用程序,我想在其中为注册用户创建一个比特币地址。 我想创建地址,以便以后可以用来接收比特币。 我如何使用 python 编程语言执行此操作。

您可以通过在您的计算机上启动一个完整节点并使用 python-bitcoinrpc 连接到它来完成此操作。 在节点完全配置并且 rpc 启动并运行后,您可以使用 AuthServiceProxy(" http://%s:%s@127.0.0.1:8332 "%(RPC_USER, RPC_PASSWORD).getnewaddress() 在 python 上获取新地址它将地址作为字符串返回。

from Crypto.PublicKey import RSA
import Crypto.Random

 def generate_keys(self):
        # those keys are in binary format.
        # Crypto.Random is the function that generates the random key.
        private_key=RSA.generate(1024, Crypto.Random.new().read)
        public_key=private_key.publickey()
        # DER is a binary format for data structures described by ASN.
        # from hex we decode it to ascii characters
        return binascii.hexlify(private_key.exportKey(format="DER")).decode('ascii'), binascii.hexlify(public_key.exportKey(format="DER")).decode('ascii')

我发现 bitmerchant 包对此很有用。

https://github.com/sbuss/bitmerchant

您可以轻松创建新钱包以及子钱包以及公钥和私钥。 github页面上的示例很容易理解。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM