aioethereum

Ethereum RPC client library for the (PEP 3156) Python event loop.

The library is intended to provide simple and clear interface to Ethereum node based on asyncio.

Features

ujson support Yes
High-level APIs Yes
HTTP support Yes
Unix domain socket (IPC) support Yes
SSL/TLS support Yes
Tested CPython versions 3.4, 3.5, 3.6
Tested Geth versions 1.7.0
Implemented RPC apis db, eth, miner, net, personal, shh, txpool, web3

Installation

The easiest way to install aioethereum is by using the package on PyPi:

pip install aioethereum

Requirements

License

The aioethereum is offered under MIT license.


Getting started

Getting started

This part of the documentation is a quick start for writing applications that interact with the client for ethereum nodes (geth, parity, etc.)

Basic API description

This client provides APIs from:

It is simple http(s)/unix connector for ethereum node which implements standart RPC methods.

API Documentation

aioethereum API

Documentation related to various APIs available in this package.

aioethereum

class aioethereum.AsyncIOHTTPClient(host='127.0.0.1', port=8545, tls=False, timeout=60, *, loop=None)

Bases: aioethereum.client.BaseAsyncIOClient, aioethereum.management.RpcMixin

Creates AsyncIOHTTPClient client to communicate via HTTP(s).

Parameters:
  • host (str) – Host on ethereum node
  • port (int) – Port on ethereum node
  • tls (bool) – Use SSL connection
  • timeout (int) – Total time of timeout call
  • loop (EventLoop) – An optional event loop instance (uses asyncio.get_event_loop() if not specified).
Returns:

AsyncIOHTTPClient instance.

class aioethereum.AsyncIOIPCClient(reader, writer, unix_path, timeout=60, *, loop=None)

Bases: aioethereum.client.BaseAsyncIOClient, aioethereum.management.RpcMixin

Creates AsyncIOIPCClient client to communicate via IPC.

Parameters:
  • reader (asyncio.streams.StreamReader) – Instance of the stream reader
  • writer (asyncio.streams.StreamWriter) – Instance of the stream writer
  • unix_path (str) – Unix domain path
  • timeout (int) – An optional total time of timeout call
  • loop (EventLoop) – An optional event loop instance (uses asyncio.get_event_loop() if not specified).
Returns:

AsyncIOIPCClient instance.

class aioethereum.BaseAsyncIOClient

Bases: abc.ABC

Abstract class for creating client.

rpc_call(method, params=None, id_=None)

Implements RPC 2.0 call to node server.

Parameters:
  • method (str) – RPC node method
  • params (list) – Input params for method
  • id (str or int) – ID of current request
Returns:

Response from RPC

coroutine aioethereum.create_ethereum_client(uri, timeout=60, *, loop=None)

Create client to ethereum node based on schema.

Parameters:
  • uri (str) – Host on ethereum node
  • timeout (int) – An optional total time of timeout call
  • loop (EventLoop) – An optional event loop instance (uses asyncio.get_event_loop() if not specified).
Returns:

BaseAsyncIOClient instance.

management

This package contains all high level features of the aioethereum.AsyncIOIPCClient and aioethereum.AsyncIOHTTPClient.

admin

Admin related features

class aioethereum.management.admin.AdminMixin

Bases: object

db

Db related features

class aioethereum.management.db.DbMixin

Bases: object

db_getHex(db_name, key)

https://github.com/ethereum/wiki/wiki/JSON-RPC#db_gethex

DEPRECATED

coroutine db_getString(db_name, key)

https://github.com/ethereum/wiki/wiki/JSON-RPC#db_getstring

DEPRECATED

coroutine db_putHex(db_name, key, value)

https://github.com/ethereum/wiki/wiki/JSON-RPC#db_puthex

DEPRECATED

coroutine db_putString(db_name, key, value)

https://github.com/ethereum/wiki/wiki/JSON-RPC#db_putstring

DEPRECATED

debug

Debug related features

class aioethereum.management.debug.DebugMixin

Bases: object

eth

Eth related features

class aioethereum.management.eth.EthMixin

Bases: object

coroutine eth_accounts()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_accounts

coroutine eth_blockNumber()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber

coroutine eth_call(from_, to=None, gas=None, gas_price=None, value=None, data=None, block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call

coroutine eth_coinbase()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_coinbase

coroutine eth_compileLLL(code)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilelll DEPRECATED

coroutine eth_compileSerpent(code)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compileserpent DEPRECATED

coroutine eth_compileSolidity(code)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilesolidity DEPRECATED

coroutine eth_estimateGas(from_, to=None, gas=None, gas_price=None, value=None, data=None)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimategas

coroutine eth_gasPrice()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice

coroutine eth_getBalance(address, block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance

coroutine eth_getBlockByHash(bhash, tx_objects=True)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbyhash

coroutine eth_getBlockByNumber(block='latest', tx_objects=True)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber

coroutine eth_getBlockTransactionCountByHash(bhash)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbyhash

coroutine eth_getBlockTransactionCountByNumber(block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbynumber

coroutine eth_getCode(address, block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode

coroutine eth_getCompilers()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcompilers DEPRECATED

coroutine eth_getFilterChanges(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges

coroutine eth_getFilterLogs(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs

coroutine eth_getLogs(from_block='latest', to_block='latest', address=None, topics=None)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs

coroutine eth_getStorageAt(address, position=0, block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat

coroutine eth_getTransactionByBlockHashAndIndex(bhash, index=0)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblockhashandindex

coroutine eth_getTransactionByBlockNumberAndIndex(block='latest', index=0)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblocknumberandindex

coroutine eth_getTransactionByHash(txhash)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash

coroutine eth_getTransactionCount(address, block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount

coroutine eth_getTransactionReceipt(txhash)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionreceipt

coroutine eth_getUncleByBlockHashAndIndex(bhash, index=0)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblockhashandindex

coroutine eth_getUncleByBlockNumberAndIndex(block='latest', index=0)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblocknumberandindex

coroutine eth_getUncleCountByBlockHash(bhash)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblockhash

coroutine eth_getUncleCountByBlockNumber(block='latest')

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber

coroutine eth_getWork()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getwork

coroutine eth_hashrate()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate

coroutine eth_mining()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_mining

coroutine eth_newBlockFilter()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newblockfilter

coroutine eth_newFilter(from_block='latest', to_block='latest', address=None, topics=None)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter

coroutine eth_newPendingTransactionFilter()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter

coroutine eth_protocolVersion()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_protocolversion

coroutine eth_sendRawTransaction(data)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendrawtransaction

coroutine eth_sendTransaction(from_, to=None, gas=None, gas_price=None, value=None, data=None, nonce=None)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction

coroutine eth_sign(address, data)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

coroutine eth_submitHashrate(hashrate, id_)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submithashrate

coroutine eth_submitWork(nonce, header, mix_digest)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submitwork

coroutine eth_syncing()

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_syncing

coroutine eth_uninstallFilter(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter

miner

Miner related features

class aioethereum.management.miner.MinerMixin

Bases: object

coroutine miner_setEtherBase(address)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner_setetherbase

NOT AVAILABLE

coroutine miner_setExtra(data)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner_setextra

Parameters:data (str) – Extra data a miner can include when miner blocks
Return type:bool
coroutine miner_setGasPrice(number)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner_setgasprice

Parameters:number (int) – Minimal accepted gas price when mining transactions
Return type:bool
coroutine miner_start(number)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner_start

Parameters:number (int) – CPU mining process with the given number of threads
Return type:bool
coroutine miner_stop()

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#miner_stop

Return type:bool
net

Net related features

class aioethereum.management.net.NetMixin

Bases: object

coroutine net_listening()

https://github.com/ethereum/wiki/wiki/JSON-RPC#net_listening

Return type:bool
coroutine net_peerCount()

https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount

Return type:int
coroutine net_version()

https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version

Return type:str
personal

Personal related features

class aioethereum.management.personal.PersonalMixin

Bases: object

coroutine personal_ecRecover(message, signature)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecrecover

Parameters:
  • message (str) – Message for sign
  • password (str) – Signature of account (optional)
Returns:

address

Return type:

hex

coroutine personal_importRawKey(keydata, passphrase)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_importrawkey

Parameters:
  • keydata (str) – Unencrypted private key
  • passphrase (str) – Passphrase of private key
Returns:

address

Return type:

hex

coroutine personal_listAccounts()

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_listaccounts

Returns:addresses
Return type:list
coroutine personal_lockAccount(address)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_lockaccount

Parameters:address (str) – Account address
Return type:bool
coroutine personal_newAccount(passphrase=None)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_newaccount

Parameters:passphrase (str) – Passphrase of account (optional)
Returns:address
Return type:hex
coroutine personal_sendTransaction(from_, to=None, gas=None, gas_price=None, value=None, data=None, nonce=None, passphrase=None)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sendtransaction

Parameters:
  • from (str) – From account address
  • to (str) – To account address (optional)
  • gas (int) – Gas amount for current transaction (optional)
  • gas_price (int) – Gas price for current transaction (optional)
  • value (int) – Amount of ether to send (optional)
  • data (str) – Additional data for transaction (optional)
  • nonce (int) – Unique nonce for transaction (optional)
  • passphrase (str) – Passphrase of account (optional)
Returns:

txhash

Return type:

hex

coroutine personal_sign(message, account, password=None)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign

Parameters:
  • message (str) – Message for sign
  • account (str) – Account address
  • password (str) – Password of account (optional)
Returns:

signature

Return type:

hex

coroutine personal_unlockAccount(address, passphrase, duration=None)

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_unlockaccount

Parameters:
  • address (str) – Account address
  • passphrase (str) – Passphrase of account
  • duration (int) – Duration to be unlocked (optional)
Return type:

bool

shh

Shh related features

class aioethereum.management.shh.ShhMixin

Bases: object

coroutine shh_addToGroup()

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_addtogroup DEPRECATED

coroutine shh_getFilterChanges(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getfilterchanges DEPRECATED

coroutine shh_getMessages(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_getmessages DEPRECATED

coroutine shh_hasIdentity(address)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_hasidentity DEPRECATED

coroutine shh_newFilter(to=None, *, topics)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newfilter DEPRECATED

coroutine shh_newGroup()

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newgroup DEPRECATED

coroutine shh_newIdentity()

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_newidentity DEPRECATED

coroutine shh_post(from_=None, to=None, *, topics, payload, priority, ttl)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_post

coroutine shh_uninstallFilter(filter_id)

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_uninstallfilter DEPRECATED

coroutine shh_version()

https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_version

txpool

Txpool related features

class aioethereum.management.txpool.TxpoolMixin

Bases: object

coroutine txpool_content()

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#txpool_content

coroutine txpool_inspect()

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#txpool_inspect

coroutine txpool_status()

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#txpool_status

web3

Web3 related features

class aioethereum.management.web3.Web3Mixin

Bases: object

coroutine web3_clientVersion()

https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion

coroutine web3_sha3(data)

https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_sha3

Glossary

asyncio

Reference implementation of PEP 3156

See https://pypi.python.org/pypi/asyncio

pytest
A mature full-featured Python testing tool. See http://pytest.org/latest/
ujson

UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3. ujson.

See https://pypi.python.org/pypi/ujson

Indices and tables