pybitcoin

CircleCI PyPI PyPI PyPI Slack

Python library with tools for Bitcoin and other cryptocurrencies.

Usage

Private Keys

>>> from pybitcoin import BitcoinPrivateKey
>>> private_key = BitcoinPrivateKey()
>>> private_key.to_hex()
'91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d'
>>> private_key.to_wif()
'5JvBUBPzU42Y7BHD7thTnySXQXMk8XEJGGQGcyBw7CCkw8RAH7m'
>>> private_key_2 = BitcoinPrivateKey('91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d')
>>> print private_key.to_wif() == private_key_2.to_wif()
True

Public Keys

>>> public_key = private_key.public_key()
>>> public_key.to_hex()
'042c6b7e6da7633c8f226891cc7fa8e5ec84f8eacc792a46786efc869a408d29539a5e6f8de3f71c0014e8ea71691c7b41f45c083a074fef7ab5c321753ba2b3fe'
>>> public_key_2 = BitcoinPublicKey(public_key.to_hex())
>>> print public_key.to_hex() == public_key_2.to_hex()
True

Addresses

>>> public_key.address()
'13mtgVARiB1HiRyCHnKTi6rEwyje5TYKBW'
>>> public_key.hash160()
'1e6db1e09b5e307847e5734864a79ea0113d0083'

Brainwallet-based Private Keys

>>> private_key = BitcoinPrivateKey.from_passphrase()
>>> private_key.passphrase()
'shepherd mais pack rate enamel horace diva filesize maximum really roar mall'
>>> private_key.to_hex()
'91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d'
>>> priv2 = BitcoinPrivateKey.from_passphrase(priv2.passphrase())
>>> print private_key.to_hex() == priv2.to_hex()
True

Sending Transactions to Addresses

>>> from pybitcoin import BlockcypherClient
>>> recipient_address = '1EEwLZVZMc2EhMf3LXDARbp4mA3qAwhBxu'
>>> blockchain_client = BlockcypherClient(BLOCKCYPHER_API_KEY)
>>> send_to_address(recipient_address, 10000, private_key.to_hex(), blockchain_client)

Sending OP_RETURN Transactions

>>> from pybitcoin import make_op_return_tx
>>> data = '00' * 80
>>> tx = make_op_return_tx(data, private_key.to_hex(), blockchain_client, fee=10000, format='bin')
>>> broadcast_transaction(tx, blockchain_client)
{"success": True}

Altcoins

>>> class NamecoinPrivateKey(BitcoinPrivateKey):
>>>     _pubkeyhash_version_byte = 52
>>> namecoin_private_key = NamecoinPrivateKey(private_key.to_hex())
>>> namecoin_private_key.to_wif()
'73zteEjenBCK7qVtG2yRPeco2TP5w93qBW5sJkxYoGYvbWwAbXv'
>>> namecoin_public_key = namecoin_private_key.public_key()
>>> namecoin_public_key.address()
'MyMFt8fQdZ6rEyDhZbe2vd19gD8gzagr7Z'

Supported currencies

Litecoin, Namecoin, Peercoin, Primecoin, Testnet, Worldcoin, Megacoin, Feathercoin, Terracoin, Novacoin, Dogecoin, Anoncoin, Protoshares, Ixcoin, Memorycoin, Infinitecoin, Cryptogenic Bullion, Quarkcoin, Netcoin, Earthcoin, Reddcoin, (insert your favorite cryptocurrency here)

Developers

Q: Can I contribute to pybitcoin?

A: Of course! Any and all are encouraged to contribute. Just fork a copy of the repo and get started on something that you think would improve the current offering.

Q: What should I work on?

A: That's up to you! For a quick project, consider adding support for a new cryptocurrency (should only require two lines of code, not including the unit tests).

Meanwhile, for something a bit more ambitious, check the issues section for outstanding feature requests.

Notice

pybitcoin is still in beta. Developers using pybitcoin are encouraged to inspect the code for themselves and perform their own tests. We are committed to ensuring that this library behaves exactly as it is supposed to under all conditions, and have plans to ramp up our testing efforts going forward.



pybitcoin

CircleCI

具有Bitcoin和其他加密货币工具的Python库。

用法

私钥

>>> from pybitcoin import BitcoinPrivateKey
>>> private_key = BitcoinPrivateKey()
>>> private_key.to_hex()
'91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d'
>>> private_key.to_wif()
'5JvBUBPzU42Y7BHD7thTnySXQXMk8XEJGGQGcyBw7CCkw8RAH7m'
>>> private_key_2 = BitcoinPrivateKey('91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d')
>>> print private_key.to_wif() == private_key_2.to_wif()
True

公钥

>>> public_key = private_key.public_key()
>>> public_key.to_hex()
'042c6b7e6da7633c8f226891cc7fa8e5ec84f8eacc792a46786efc869a408d29539a5e6f8de3f71c0014e8ea71691c7b41f45c083a074fef7ab5c321753ba2b3fe'
>>> public_key_2 = BitcoinPublicKey(public_key.to_hex())
>>> print public_key.to_hex() == public_key_2.to_hex()
True

地址

>>> public_key.address()
'13mtgVARiB1HiRyCHnKTi6rEwyje5TYKBW'
>>> public_key.hash160()
'1e6db1e09b5e307847e5734864a79ea0113d0083'

基于Brainwallet的私钥

>>> private_key = BitcoinPrivateKey.from_passphrase()
>>> private_key.passphrase()
'shepherd mais pack rate enamel horace diva filesize maximum really roar mall'
>>> private_key.to_hex()
'91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d'
>>> priv2 = BitcoinPrivateKey.from_passphrase(priv2.passphrase())
>>> print private_key.to_hex() == priv2.to_hex()
True

将交易发送到地址

>>> from pybitcoin import BlockcypherClient
>>> recipient_address = '1EEwLZVZMc2EhMf3LXDARbp4mA3qAwhBxu'
>>> blockchain_client = BlockcypherClient(BLOCKCYPHER_API_KEY)
>>> send_to_address(recipient_address, 10000, private_key.to_hex(), blockchain_client)

Altcoins

>>> class NamecoinPrivateKey(BitcoinPrivateKey):
>>>     _pubkeyhash_version_byte = 52
>>> namecoin_private_key = NamecoinPrivateKey(private_key.to_hex())
>>> namecoin_private_key.to_wif()
'73zteEjenBCK7qVtG2yRPeco2TP5w93qBW5sJkxYoGYvbWwAbXv'
>>> namecoin_public_key = namecoin_private_key.public_key()
>>> namecoin_public_key.address()
'MyMFt8fQdZ6rEyDhZbe2vd19gD8gzagr7Z'

支持货币

Litecoin,Namecoin,Peercoin,Primecoin,Testnet,Worldcoin,Megacoin,Feathercoin,Terracoin,Novacoin,Dogecoin,Anoncoin,Protoshares,Ixcoin,Memorycoin,Infinitecoin,Cryptogenic Bullion,Quarkcoin,Netcoin,Earthcoin,Reddcoin(插入您最喜爱的这里的cryptocurrency)

开发人员

问:我可以为pybitcoin做贡献吗?

A:当然!鼓励任何人都贡献。只需分配一份备份,并开始使用您认为可以改善当前产品的内容。

问:我该怎么办?

A:这取决于你!对于一个快速的项目,考虑添加对新的加密的支持(应该只需要两行代码,不包括单元测试)。

同时,对于更有意义的东西,请查看问题部分了解未完成的功能请求。

通知

pybitcoin仍处于测试阶段。鼓励使用pybitcoin的开发人员自行检查代码并执行自己的测试。我们致力于确保这种图书馆的行为与所有条件下的行为完全一致,并计划推进我们的测试工作。




相关问题推荐