Introduction
Nodes created by the current generation of Ethereum clients expose inconsistent and incompatible remote procedure call (RPC) methods because no formal Ethereum RPC specification exists. This proposal standardizes such a specification to provide developers with a predictable Ethereum RPC interface regardless of underlying node implementation.
Ethereum JSON RPC
web3_clientVersion
curl -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://localhost:8545
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":67,"result":"Geth/v1.8.21-stable/linux-amd64/go1.11.4"}
Returns the version of the current client
web3_sha3
curl -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}' http://localhost:8545
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":64,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}
Hashes data using the Keccak-256 algorithm
Parameters
DATA - the data to convert into a SHA3 hash.
params: [
"0x68656c6c6f20776f726c64"
]
Returns
DATA - The SHA3 result of the given string.
net_listening
curl -X POST --header "Content-Type: application/json" --data '{"id": 1337,"jsonrpc": "2.0","method": "net_listening","params": []}' http://localhost:75
45
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":1337,"result":true}
Determines if this client is listening for new network connections
Parameters
(none)
Returns
{boolean
} - true
if listening is active or false
if listening is not active
net_peerCount
curl -X POST --header "Content-Type: application/json" --data '{"id": 1337,"jsonrpc": "2.0","method": "net_peerCount","params": []}' http://localhost:7545
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":1337,"result":"0x19"}
Returns the number of peers currently connected to this client
Parameters
(none)
Returns
{Quantity
} - number of connected peers
net_version
curl -X POST --header "Content-Type: application/json" --data '{"id": 1337, "jsonrpc": "2.0","method": "net_version","params": []}' http://localhost:8545
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":1337,"result":"1"}
Returns the chain ID associated with the current network
Parameters
(none)
Returns
{string
} - chain ID associated with the current network
Common chain IDs:
- "1" - Ethereum mainnet
- "3" - Ropsten testnet
- "4" - Rinkeby testnet
- "42" - Kovan testnet
Note: See EIP-155 for a complete list of possible chain IDs.
eth_accounts
curl -X POST --header "Content-Type: application/json" --data '{"id": 1337,"jsonrpc": "2.0","method": "eth_accounts","params": []}' http://localhost:8545
The above command returns JSON structured like this:
{
"id": 1337,
"jsonrpc": "2.0",
"result": ["0xc94770007dda54cF92009BFF0dE90c06F603a09f"]
}
Returns a list of addresses owned by this client
Parameters
(none)
Returns
{Data[]
} - array of addresses
eth_blockNumber
curl -X POST --header "Content-Type: application/json" --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": []
}' http://localhost:7545
The above command returns JSON structured like this:
{"jsonrpc":"2.0","id":1337,"result":"0x6e9c4e"}
Returns the number of the most recent block seen by this client
Parameters
(none)
Returns
{Quantity
} - number of the latest block
eth_call
curl -X POST --header "Content-Type: application/json" --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"value": "0x9184e72a"
}]
}' http://localhost:7545
The above command returns JSON structured like this:
{
"id": 1337,
"jsonrpc": "2.0",
"result": "0x"
}
Executes a new message call immediately without submitting a transaction to the network
Parameters
# | Type | Description |
---|---|---|
1 | {object } |
@property {Data } [from] - transaction sender@property { Data } to - transaction recipient or null if deploying a contract@property { Quantity } [gas] - gas provided for transaction execution@property { Quantity } [gasPrice] - price in wei of each gas used@property { Quantity } [value] - value in wei sent with this transaction@property { Data } [data] - contract code or a hashed method call with encoded args |
2 | {Quantity \ |
string } |
Returns
{Data
} - return value of executed contract
eth_coinbase
curl -X POST --header "Content-Type: application/json" --data '{
"id": 1337,
"jsonrpc": "2.0",
"method": "eth_coinbase",
"params": []
}' http://localhost:7545
The above command returns JSON structured like this:
{
"id": 1337,
"jsonrpc": "2.0",
"result": "0xc94770007dda54cF92009BFF0dE90c06F603a09f"
}
Returns the coinbase address for this client
Parameters
(none)
Returns
{Data
} - coinbase address
Errors
Code | Message | Meaning | Category |
---|---|---|---|
-32700 | Parse error | Invalid JSON | standard |
-32600 | Invalid request | JSON is not a valid request object | standard |
-32601 | Method not found | Method does not exist | standard |
-32602 | Invalid params | Invalid method parameters | standard |
-32603 | Internal error | Internal JSON-RPC error | standard |
-32000 | Invalid input | Missing or invalid parameters | non-standard |
-32001 | Resource not found | Requested resource not found | non-standard |
-32002 | Resource unavailable | Requested resource not available | non-standard |
-32003 | Transaction rejected | Transaction creation failed | non-standard |
-32004 | Method not supported | Method is not implemented | non-standard |
Example error response:
{
"id": 1337
"jsonrpc": "2.0",
"error": {
"code": -32003,
"message": "Transaction rejected"
}
}