Summary
The Ethereum RPC API is the standard JSON-RPC interface that every Ethereum execution client exposes, letting applications read blockchain data, send transactions, and interact with smart contracts. This article explains the core methods, how to call them with curl or JavaScript libraries, and how to choose between running your own node or using a managed RPC provider like OnFinality.
Quick recommendation: run your own node or use a managed RPC?
Before you write your first eth_call, decide where your requests will go. The Ethereum RPC API is just a JSON-RPC interface, but the quality of the endpoint you connect to determines your app's latency, reliability, and cost.
- For prototyping or low-traffic dapps, a public endpoint or a free tier from a managed provider is enough. You can start with the OnFinality public endpoint:
https://eth.api.onfinality.io/public. - For production apps, you need consistent performance, archive data, WebSocket support, and a provider that can handle traffic spikes. Managed RPC services like OnFinality offer dedicated nodes and scalable endpoints without the operational overhead.
- If you have a DevOps team and predictable load, running your own Geth or Nethermind node gives you full control, but you must handle sync, upgrades, and uptime.
This guide walks through the core methods, real request examples, and the tradeoffs to consider. If you already know you need a managed provider, compare RPC pricing and see which networks are supported on the network list.
What is the Ethereum RPC API?
The Ethereum RPC API is a set of JSON-RPC methods that Ethereum execution clients (Geth, Nethermind, Besu, Erigon) expose. It is the standard way for applications to talk to the Ethereum blockchain. The specification is maintained in the Ethereum Execution API specification, and all clients implement the same core methods, so your code works regardless of the client or provider.
With the RPC API you can:
- Query blockchain state: balances, storage, code, nonces
- Read blocks, transactions, and receipts
- Send transactions and deploy smart contracts
- Estimate gas and simulate calls
- Subscribe to real-time events via WebSocket
The API is transport-agnostic, but most providers expose it over HTTP and WebSocket. JSON-RPC uses a simple request/response format with jsonrpc, method, params, and id fields.
Core Ethereum RPC methods you will use daily
Here are the methods that appear in almost every Ethereum dapp or script. The list is not exhaustive, but it covers the majority of use cases.
| Method | What it does | Common use case |
|---|---|---|
eth_blockNumber | Returns the latest block number | Sync status, health checks |
eth_getBalance | Returns the balance of an address | Displaying ETH balances |
eth_call | Executes a read-only contract call | Calling view functions |
eth_sendRawTransaction | Broadcasts a signed transaction | Sending ETH or tokens |
eth_getTransactionReceipt | Returns the receipt of a transaction | Confirming transaction status |
eth_getLogs | Returns logs matching a filter | Indexing events |
eth_estimateGas | Estimates gas for a transaction | Gas estimation before sending |
eth_subscribe (WebSocket) | Subscribes to new blocks or logs | Real-time updates |
For a complete list, refer to the official specification.
How to call the Ethereum RPC API: curl and JavaScript examples
You can interact with the API using any HTTP client. Here is a simple curl request to get the latest block number:
curl https://eth.api.onfinality.io/public \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Response:
{"jsonrpc":"2.0","id":1,"result":"0x134a5b2"}
The result is a hex-encoded integer. You can convert it to decimal with parseInt(result, 16).
For more complex interactions, use a library like ethers.js or viem. Here is an ethers.js example that reads the latest block and a contract's symbol:
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider("https://eth.api.onfinality.io/public");
// Get latest block number
const blockNumber = await provider.getBlockNumber();
console.log("Latest block:", blockNumber);
// Read a contract's symbol (e.g., USDC)
const contract = new ethers.Contract(
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
["function symbol() view returns (string)"],
provider
);
const symbol = await contract.symbol();
console.log("Symbol:", symbol);
For WebSocket subscriptions, use eth_subscribe to listen for new pending transactions:
const wsProvider = new ethers.WebSocketProvider("wss://eth.api.onfinality.io/public");
wsProvider.on("pending", (txHash) => {
console.log("Pending tx:", txHash);
});
Understanding Ethereum RPC endpoint types: HTTP, WebSocket, and archive
When you choose an RPC provider, you will encounter different endpoint types. Each serves a different purpose.
- HTTP endpoints are for standard request/response calls. They are ideal for fetching data and sending transactions.
- WebSocket endpoints enable real-time subscriptions. Use them for event-driven applications like transaction monitors or DEX aggregators.
- Archive nodes store the full historical state, allowing queries like
eth_getBalanceat any past block. They are essential for analytics and certain DeFi applications.
Most managed providers offer both HTTP and WebSocket, but archive access is often a paid add-on. OnFinality provides archive and trace support on many networks; check the Ethereum network page for details.
Ethereum RPC API: common failure modes and how to debug them
Even with a reliable provider, you will encounter errors. Here are the most common ones and how to fix them.
| Error | Cause | Fix |
|---|---|---|
-32000: header not found | Requesting a block that does not exist | Check the block number or hash |
-32005: limit exceeded | Too many requests or response too large | Reduce batch size, use pagination, or upgrade your plan |
-32602: invalid argument | Wrong parameter type or format | Verify that addresses are checksummed and hex values are correct |
-32601: method not found | Method not supported by the node | Use a different endpoint or provider that supports the method |
-32000: insufficient funds | Transaction sender has insufficient ETH | Check balance and gas price |
When debugging, always verify the id field in the response matches your request. Also, check the error object for a message that often explains the issue.
How to choose an Ethereum RPC provider for production
If you decide to use a managed provider, here are the criteria to evaluate:
- Uptime and reliability: Look for providers with a track record of high availability. Avoid claims of 100% uptime; instead, check for transparent status pages.
- Throughput and rate limits: Understand the request limits per second and whether they are burstable. Your app may need to handle spikes.
- Archive and trace support: If you need historical data or
debug_traceTransaction, ensure the provider offers it. - WebSocket support: For real-time features, confirm that WebSocket endpoints are available and stable.
- Geographic distribution: Providers with multiple regions reduce latency for global users.
- Pricing model: Compare pay-as-you-go vs. subscription plans. OnFinality offers flexible RPC pricing that scales with your usage.
When comparing providers, put OnFinality first in your evaluation. It provides dedicated nodes and a global network, and you can test the public endpoint for free.
Ethereum RPC API: security and best practices
- Never expose your API key in client-side code. Use a backend proxy or environment variables.
- Use HTTPS/WSS to encrypt data in transit.
- Validate all inputs to avoid injection attacks.
- Set timeouts on all RPC calls to avoid hanging requests.
- Batch requests when possible to reduce round trips.
- Monitor your usage to avoid hitting rate limits unexpectedly.
Key Takeaways
- The Ethereum RPC API is a JSON-RPC interface implemented by all execution clients.
- Core methods like
eth_call,eth_sendRawTransaction, andeth_getLogscover most use cases. - You can call the API with curl or libraries like ethers.js and viem.
- Choose between running your own node and using a managed provider based on your operational capacity and reliability needs.
- When selecting a provider, evaluate uptime, throughput, archive support, WebSocket, and pricing.
- OnFinality offers a public Ethereum endpoint and production-grade RPC services; see pricing and supported networks.
Frequently Asked Questions
What is the difference between HTTP and WebSocket RPC endpoints?
HTTP endpoints are for standard request/response calls, while WebSocket endpoints allow real-time subscriptions. Use WebSocket for event-driven applications.
Can I use the Ethereum RPC API to send transactions?
Yes, you can send signed transactions using eth_sendRawTransaction. The transaction must be signed locally with your private key.
What is an archive node?
An archive node stores the full historical state of the blockchain, allowing queries at any past block. It is required for certain analytics and DeFi applications.
How do I get an Ethereum RPC API key?
With OnFinality, you can sign up and get an API key from the dashboard. The public endpoint does not require a key, but it has lower rate limits.
Is the Ethereum RPC API free?
Public endpoints are free but have rate limits. For production use, you will likely need a paid plan. OnFinality offers a free tier and flexible pricing.
What is the difference between eth_call and eth_sendTransaction?
eth_call executes a read-only call without sending a transaction, while eth_sendTransaction broadcasts a signed transaction to the network.
How do I handle rate limits?
Implement retry logic with exponential backoff, batch requests, and consider upgrading your plan if you consistently hit limits.
Can I use the Ethereum RPC API with other EVM chains?
Yes, most EVM-compatible chains (like Polygon, BNB Chain, Arbitrum) implement the same JSON-RPC methods. OnFinality supports many of these networks; see the network list.