Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.31 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.31 KB

aiojsonrpc

Python asyncio client interface fo JSON-RPC 2.0

Example

import asyncio
import aiojsonrpc

async def test(loop):
    t = aiojsonrpc.rpc("http://user:password@host:port", loop)
    while 1:
        p = await  t.getinfo()
        print(p)
        await asyncio.sleep(10)


loop = asyncio.get_event_loop()
loop.create_task(test(loop))
loop.run_forever()
python3 test.py 
{'timeoffset': 0, 'version': 140200, 'relayfee': 1e-05, 'connections': 18, 'difficulty': 708659466230.332, 'proxy': '', 'testnet': False, 'errors': '', 'blocks': 475003, 'protocolversion': 70015}

import asyncio
import aiojsonrpc

async def test(loop):
    t = aiojsonrpc.rpc("http://user:password@host:port  ", loop)
    while 1:
        p = await t.batch([["net_peerCount"],
                           ["net_peerCount"],
                           ["eth_getTransactionByHash",
                            "0xbcad8332d6d68344389f69ec547ecea4a838a2a2cab50407cf7d082531a7c058"]])
        print(p)
        await asyncio.sleep(10)

loop = asyncio.get_event_loop()
loop.create_task(test(loop))
loop.run_forever()

python3 test.py 
[{'jsonrpc': '2.0', 'id': 1, 'result': '0x19'}, {'jsonrpc': '2.0', 'id': 2, 'result': '0x19'}, {'jsonrpc': '2.0', 'id': 3, 'result': None}]