Skip to main content

What is JSON-RPC?

JSON-RPC is a lightweight, remote procedure call (RPC) protocol that uses JSON to encode messages. It enables applications to invoke methods on remote systems as if they were local.

Key Characteristics

  • Protocol-Agnostic - Works over HTTP, WebSocket, and other transports
  • Stateless - Each request is independent
  • Lightweight - JSON formatting minimizes overhead while remaining human-readable

Request Structure

A JSON-RPC request contains:
FieldDescription
jsonrpcProtocol version (always “2.0”)
methodName of the method to call
paramsMethod parameters (array or object)
idUnique request identifier

Example Request

{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest"],
  "id": 1
}

Response Structure

FieldDescription
jsonrpcProtocol version
resultMethod result (if successful)
errorError object (if failed)
idMatching request identifier

Example Response

{
  "jsonrpc": "2.0",
  "result": "0x1234567890abcdef",
  "id": 1
}

Common Methods

MethodDescription
eth_blockNumberGet the latest block number
eth_getBalanceGet account balance
eth_getTransactionByHashGet transaction details
eth_sendRawTransactionSubmit a signed transaction
eth_callExecute a read-only contract call
eth_getLogsGet event logs

Use Cases

  • Wallets - Query balances and submit transactions
  • dApps - Interact with smart contracts
  • Indexers - Fetch and process blockchain data
  • Trading Bots - Monitor state and execute trades