Skip to main content

Ethereum JSON RPC Client

Project description

# Ethereum RPC Client

[![Build Status](https://travis-ci.org/pipermerriam/ethereum-rpc-client.png)](https://travis-ci.org/pipermerriam/ethereum-rpc-client)
[![Documentation Status](https://readthedocs.org/projects/ethereum-rpc-client/badge/?version=latest)](https://readthedocs.org/projects/ethereum-rpc-client/?badge=latest)
[![PyPi version](https://pypip.in/v/ethereum-rpc-client/badge.png)](https://pypi-hypernode.com/pypi/ethereum-rpc-client)
[![PyPi downloads](https://pypip.in/d/ethereum-rpc-client/badge.png)](https://pypi-hypernode.com/pypi/ethereum-rpc-client)


Python client for Ethereum JSON RPC Server

> Note that this currently only implements a handful of the JSON RPC methods
> exposed by the server.

## Installation

Install with `pip`

```bash
$ pip install ethereum-rpc-client
```

## Basic Usage

Assuming you have an Ethereum node running the JSON RPC server on `localhost:8454`


```python
>>> from eth_rpc_client import Client
>>> client = Client(host="127.0.0.1", port="8545")
>>> client.get_coinbase()
... '0xd3cda913deb6f67967b99d67acdfa1712c293601'
```

## API

### `Client.get_coinbase()`

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

Returns the hex encoded coinbase.

### `Client.get_gas_price()`

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

Returns the gas price in wei as an integer

### `Client.get_balance(address, block="latest")`

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

* **address**: The hex encoded address to lookup the balance for.
* **block**: The block to use for the lookup.

Returns the account balance for the address in wei as an integer.

### `Client.get_code(address, block="latest")`

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

* **address**: The hex encoded address to lookup the code for.
* **block**: The block to use for the lookup.

Returns the code at the given address.

### `Client.call(_from=None, to=None, gas=None, gas_price=None, value=0, data=None, block="latest")`

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

* **_from**: The hex encoded address to use as the source for the call.
* **to**: The hex encoded address of the contract for the call.
* **gas**: Integer gas alotment for the call.
* **gas_price**: Integer gas price in wei.
* **value**: Integer amount in wei to send with the call.
* **data**: The call data.

Returns the call response.

### `Client.send_transaction(_from=None, to=None, gas=None, gas_price=None, value=0, data=None)

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

* **_from**: The hex encoded address to use as the source for the transaction.
* **to**: The hex encoded address of the contract for the transaction.
* **gas**: Integer gas alotment for the transaction.
* **gas_price**: Integer gas price in wei.
* **value**: Integer amount in wei to send with the transaction.
* **data**: The transaction data.

### `Client.get_transaction_receipt(txn_hash)`

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

* **txn_hash**: The hex encoded transaction hash to lookup.

Returns a dictionary of the transaction receipt or `None` if no receipt is
found.

* **transactionHash**: hex encoded hash of the transaction.
* **transactionIndex**: integer of the transactions index position in the block.
* **blockHash**: hex encoded hash of the block where this transaction was in.
* **blockNumber**: integer block number where this transaction was in.
* **cumulativeGasUsed**: The total amount of gas used when this transaction was executed in the block.
* **gasUsed**: The amount of gas used by this specific transaction alone.
* **contractAddress**: The contract address created, if the transaction was a contract creation, otherwise null.
* **logs**: list of log objects, which this transaction generated


### `Client.get_transaction_by_hash(txn_hash)`

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

* **txn_hash**: The hex encoded transaction hash to lookup.

Returns a dictionary of the transaction values or `None` if no transaction is
found.

* **hash**: DATA, 32 Bytes - hash of the transaction.
* **nonce**: QUANTITY - the number of transactions made by the sender prior to this one.
* **blockHash**: DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.
* **blockNumber**: QUANTITY - block number where this transaction was in. null when its pending.
* **transactionIndex**: QUANTITY - integer of the transactions index position in the block. null when its pending.
* **from**: DATA, 20 Bytes - address of the sender.
* **to**: DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.
* **value**: QUANTITY - value transferred in Wei.
* **gasPrice**: QUANTITY - gas price provided by the sender in Wei.
* **gas**: QUANTITY - gas provided by the sender.
* **input**: DATA - the data send along with the transaction.


### `Client.get_block_number()`

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

Returns the number of the most recent block.


### `Client.get_accounts()`

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

Returns a list of the addresses owned by the client.


### `Client.new_filter(from_block=None, to_block=None, address=None, topics=None)`

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


### `Client.new_block_filter()`

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


### `Client.new_pending_transaction_filter()`

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


### `Client.uninstall_filter(filter_id)`

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


### `Client.get_filter_changes(filter_id)`

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


### `Client.get_filter_logs(filter_id)`

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


### `Client.get_logs(from_block=None, to_block=None, address=None, topics=None)`

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


## Helpers

### `Client.get_max_gas()`

Returns the gas limit from the latest block


### `Client.wait_for_transaction(txn_hash, max_wait=60)`

Blocks for up to `max_wait` seconds, polling for the transaction receipt for
the provided `txn_hash`. Returns the transaction hash.


### `Client.wait_for_block(block_number, max_wait=60)`

Blocks for up to `max_wait` seconds, polling the rpc server until the block
specified by `block_number` is seen. Returns the block.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethereum-rpc-client-0.4.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distributions

ethereum_rpc_client-0.4.2-py2-none-any.whl (8.1 kB view details)

Uploaded Python 2

File details

Details for the file ethereum-rpc-client-0.4.2.tar.gz.

File metadata

File hashes

Hashes for ethereum-rpc-client-0.4.2.tar.gz
Algorithm Hash digest
SHA256 318f3681f0253978265cfc33513b820bad89bd8a3d06cac6b9d3fc4bb1a97eb0
MD5 f397e98fcde22128ba31e66bd9a8dd11
BLAKE2b-256 d36ee61742770f35b2bfef1dada6cc2e745c73b04f15440570566c7797c364ab

See more details on using hashes here.

File details

Details for the file ethereum_rpc_client-0.4.2-py2-none-any.whl.

File metadata

File hashes

Hashes for ethereum_rpc_client-0.4.2-py2-none-any.whl
Algorithm Hash digest
SHA256 cfb2e39f5fb17daa50be150bec5d5e7ac53cf96826e8013c74b2129885eefe0c
MD5 a41a12d6209d19844455ee7b75adcfc7
BLAKE2b-256 516b849652a1c56f911e10c90b8a757f9e1edbc54622ee4ed5f1a996c0d9f8c4

See more details on using hashes here.

File details

Details for the file ethereum-rpc-client-0.4.2.macosx-10.11-x86_64.tar.gz.

File metadata

File hashes

Hashes for ethereum-rpc-client-0.4.2.macosx-10.11-x86_64.tar.gz
Algorithm Hash digest
SHA256 1fa16b94d31a435ab4f15b36a2df5c0659f88210e37b832e9c221c5c445c9fbc
MD5 62a9b971b728507a5176d7986b3c3b86
BLAKE2b-256 670aa383ee4b19a257e87f7c27e55b5790bf615dc801418934cf16d6c6fde3f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page