项目作者: biobdeveloper

项目描述 :
Python 3 async BitCoin RPC-client library
高级语言: Python
项目地址: git://github.com/biobdeveloper/aiobtcrpc.git
创建时间: 2020-12-18T12:55:17Z
项目社区:https://github.com/biobdeveloper/aiobtcrpc

开源协议:MIT License

下载


AioBtcRpc

Modern Python3 async aiohttp-based JSONRPC client
for Bitcoin Core.

Allow to use any Bitcoin RPC method

VersionLicense

Install

  1. pip install aiobtcrpc

Usage

Pretty simple:

await BitcoinCoreClient.anybitcoinrpcmethodname(*args_in_order_like_in_the_docs)

  1. import asyncio
  2. from aiobtcrpc import BitcoinCoreClient, JSONRPCException
  3. async def test():
  4. # Create client object by providing rpc-server url to BitcoinCoreClient class
  5. cli = BitcoinCoreClient(rpc_url="https://USER:PASSWROD@HOST:PORT")
  6. # Just execute cli.ANY_RPC_COMMAND(*args)
  7. balance = await cli.getbalance()
  8. # all float values returns as python decimal.Decimal object
  9. print(balance)
  10. # >>> 0.02587228
  11. # Unlock your wallet
  12. unlock = await cli.walletpassphrase("Your wallet.dat server bitcoin password", 10)
  13. # Donate me
  14. donate_tx = await cli.sendtoaddress("1EWGKaAdof35pdjBnQW9xh7dwRVJkA8vUR", 0.01)
  15. print(donate_tx)
  16. # >>> bd38d3e6c7ab8c25e183e818829e1f0e179af12ef418fa6f4f27c76ef77c924
  17. # Errors are raises as JSONRPCException with .code and .message attrs
  18. try:
  19. await cli.walletpassphrase("BadPassword")
  20. except JSONRPCException as ex:
  21. print(ex.code, ex.message)
  22. # >>> -14 Error: The wallet passphrase entered was incorrect.
  23. asyncio.run(test())