EIP-1474 · Stagnant · Interface · 2018-10-02
EIP-1474: Remote procedure call specification
An attempt to write down one formal JSON-RPC specification for Ethereum nodes (methods, value encoding and error codes) so dapps get the same behaviour from every client.
What problem does it solve?
Wallets, libraries and dapps talk to Ethereum nodes over JSON-RPC (eth_getBalance, eth_call, eth_sendRawTransaction…). In 2018 there was no formal spec for these methods, only client documentation and a wiki page. Clients differed in method signatures, encodings and error behaviour, so applications had to work around each node's quirks.
EIP-1474 collects the methods into one document and makes it changeable through the normal EIP process.
How it works
The proposal defines three layers:
- Transport. Every call is a JSON-RPC 2.0 request object and must get a JSON-RPC 2.0 response object.
- Value encoding.
Quantity(numbers):0x-prefixed hex with no leading zeros; zero is0x0. So0x400is valid and0x0400is not.Data(bytes):0x-prefixed hex, two digits per byte.0xis empty data,0x00is one zero byte.- Block parameters may be a block number, a tag such as
latest, or (per EIP-1898) an object{ blockHash, requireCanonical }.
- Errors. Besides the standard JSON-RPC codes (
-32700…-32603), it reserves Ethereum-specific codes, for example-32000invalid input,-32001resource not found,-32003transaction rejected,-32004method not supported and-32005limit exceeded.
It then documents each method's parameters, return values and an example: web3_*, net_* and the eth_* family, including blocks, transactions, receipts, logs and filters, eth_call, eth_estimateGas, signing, and the old mining methods.
Sample code
A raw request, exactly as the spec frames it:
curl -X POST -H "Content-Type: application/json" --data '{
"id": 1, "jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x0000000000000000000000000000000000000000", "latest"]
}' "$RPC_URL"
# -> {"id":1,"jsonrpc":"2.0","result":"0x..."} (a Quantity, in wei)
The same call through ethers v6, which handles the encoding for you:
import { JsonRpcProvider, toQuantity } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const hex = await provider.send("eth_getBalance", [someAddress, "latest"]);
console.log(BigInt(hex)); // decode Quantity
console.log(toQuantity(1024)); // "0x400" - encode, no leading zeros
Things to know
- Status is Stagnant. The living reference for node APIs is now the community-maintained Ethereum execution-apis specification (OpenRPC-based), rather than this EIP. EIP-1901 proposed the OpenRPC
rpc.discoverapproach. - Some methods listed here are obsolete on today's network, notably the proof-of-work mining calls (
eth_getWork,eth_submitWork,eth_hashrate) and the uncle queries. - Error codes beyond
-32603are still not used identically by every client, so do not rely on exact codes for control flow without testing your provider.