Skip to content

JSON-RPC Methods

SpeedyNodes provides access to blockchain networks through the JSON-RPC protocol. This section covers the available methods you can use to interact with our RPC endpoints.

What is JSON-RPC?

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol that uses JSON (RFC 4627) as its data format. It is designed to be simple and easy to use. A JSON-RPC call is represented by sending a request object to a server implementing the protocol.

Request Format

A basic JSON-RPC request has the following structure:

{
  "jsonrpc": "2.0",
  "method": "method_name",
  "params": [param1, param2, ...],
  "id": 1
}
  • jsonrpc: Specifies the JSON-RPC version, always "2.0"
  • method: The method to be invoked on the server
  • params: An array or object of parameters to pass to the method
  • id: An identifier for the request, used to match responses with requests

Response Format

A successful JSON-RPC response has the following structure:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "the_result_value"
}

If there's an error, the response will look like:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32601,
    "message": "Method not found"
  }
}

Namespaces

JSON-RPC methods are organized into namespaces based on their functionality:

  • eth: Core Ethereum protocol methods
  • net: Network status methods
  • web3: Web3 utility methods
  • txpool: Transaction pool information methods
  • debug: Debugging methods (available on both full and archive nodes)
  • trace: Transaction tracing methods (available on archive nodes only)

Making JSON-RPC Calls

Using Curl

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://api.speedynodes.net/http/eth-http?apikey=YOUR_API_KEY

Using Web3.js

const Web3 = require('web3');
const web3 = new Web3('https://api.speedynodes.net/http/eth-http?apikey=YOUR_API_KEY');

// Using the standard Web3 methods
web3.eth.getBlockNumber()
  .then(console.log);

// Making a custom RPC call
web3.eth.getBlockNumber = web3.eth.getBlockNumber || function() {
  return web3.currentProvider.send({
    jsonrpc: '2.0',
    method: 'eth_blockNumber',
    params: [],
    id: new Date().getTime()
  })
  .then(response => {
    return parseInt(response.result, 16);
  });
};

Using Ethers.js

const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://api.speedynodes.net/http/eth-http?apikey=YOUR_API_KEY');

// Using the standard Ethers methods
provider.getBlockNumber()
  .then(console.log);

// Making a custom RPC call
provider.send('eth_blockNumber', [])
  .then(hexResult => {
    console.log(parseInt(hexResult, 16));
  });

Common Error Codes

Code Message Description
-32700 Parse error Invalid JSON
-32600 Invalid Request The JSON sent is not a valid Request object
-32601 Method not found The method does not exist / is not available
-32602 Invalid params Invalid method parameter(s)
-32603 Internal error Internal JSON-RPC error
-32000 to -32099 Server error Reserved for implementation-defined server errors

Common Methods by Namespace

eth Namespace

The eth namespace includes methods for interacting with the Ethereum blockchain:

Method Description Parameters
eth_blockNumber Returns the current block number []
eth_getBalance Returns the balance of an account ["address", "block_parameter"]
eth_sendRawTransaction Sends a signed transaction ["signed_transaction_data"]
eth_call Executes a message call [transaction_object, block_parameter]
eth_getTransactionByHash Returns transaction information by hash ["transaction_hash"]
eth_getLogs Returns logs matching the filter criteria [filter_object]
eth_getBlockByNumber Returns block information by number [block_parameter, show_transaction_details]
eth_getBlockByHash Returns block information by hash ["block_hash", show_transaction_details]
eth_getTransactionReceipt Returns the receipt of a transaction ["transaction_hash"]
eth_getCode Returns the code at a given address ["address", block_parameter]
eth_estimateGas Returns an estimation of gas required for a transaction [transaction_object, block_parameter]
eth_gasPrice Returns the current gas price []
eth_getStorageAt Returns the value from storage at a given position ["address", "position", block_parameter]
eth_getTransactionCount Returns the number of transactions sent from an address ["address", block_parameter]

net Namespace

The net namespace includes methods for retrieving network information:

Method Description Parameters
net_version Returns the current network ID []
net_listening Returns if client is actively listening for network connections []
net_peerCount Returns number of peers currently connected to the client []

web3 Namespace

The web3 namespace includes utility methods:

Method Description Parameters
web3_clientVersion Returns the current client version []
web3_sha3 Returns Keccak-256 hash of the given data ["data"]

txpool Namespace

The txpool namespace includes methods for working with the transaction pool:

Method Description Parameters
txpool_content Returns the transactions currently pending in the transaction pool []
txpool_status Returns the number of transactions currently pending in the transaction pool []
txpool_inspect Returns a textual summary of all transactions currently pending in the transaction pool []

debug Namespace (Full and Archive Nodes)

The debug namespace includes methods for debugging:

Method Description Parameters
debug_traceTransaction Returns the structured logs created during the execution of a transaction ["transaction_hash", options]
debug_traceCall Executes a call and returns a structured log of its execution [transaction_object, block_parameter, options]
debug_traceBlockByNumber Returns the structured logs created during the execution of all transactions in the block [block_number, options]
debug_traceBlockByHash Returns the structured logs created during the execution of all transactions in the block ["block_hash", options]

trace Namespace (Archive Nodes Only)

The trace namespace includes methods for tracing transactions, available only on archive nodes:

Method Description Parameters
trace_transaction Returns all traces of a given transaction ["transaction_hash"]
trace_get Returns a specific trace from a transaction ["transaction_hash", trace_index, trace_indices]
trace_block Returns traces created at the given block [block_parameter]
trace_filter Returns traces matching the given filter [filter_object]
trace_call Traces a call to eth_call [transaction_object, trace_types, block_parameter]
trace_rawTransaction Traces a call to eth_sendRawTransaction ["raw_transaction", trace_types]