Logo
New RPC users get 35% off their first monthView the offer
RPC Assistant

Ethereum Blockchain API: JSON-RPC Methods, WebSocket & Examples

Summary

The Ethereum blockchain API is the JSON-RPC interface that lets applications read from and write to the Ethereum network without running a local node. It exposes core methods such as eth_call for read-only contract simulation, eth_getLogs for filtered event history, eth_sendRawTransaction for broadcasting signed transactions, eth_getTransactionReceipt for confirming inclusion, and eth_estimateGas for gas planning. Every request carries jsonrpc, method, params, and id fields; the response returns a result object or a JSON-RPC error. Access is available over HTTPS for standard request/response patterns and WebSocket for push-based subscriptions like newHeads, logs, and pending transactions. Optional Trace and Debug APIs provide deeper execution tracing but are separate entry points from core methods and not universally available. For production, connect through a managed endpoint such as OnFinality, verify archive and regional access on the Ethereum network page, and keep mainnet chain ID 1 distinct from Sepolia chain ID 11155111. Sign transactions locally and submit via eth_sendRawTransaction; use eth_call for reads and eth_estimateGas before sending.

Key Takeaways

  • The Ethereum blockchain API is JSON-RPC over HTTPS or WebSocket; master eth_call, eth_getLogs, eth_sendRawTransaction, receipts, and gas estimation.
  • Separate core execution methods from optional Trace/Debug APIs and the Beacon consensus REST API.
  • Use HTTP for request/response and WebSocket for subscriptions; build reconnect and resubscription logic.
  • Verify chain IDs, archive availability, rate limits, and regional access on the OnFinality network page before production.

How the Ethereum Blockchain API Works

The Ethereum blockchain API is the JSON-RPC interface exposed by Ethereum execution clients. Every request is a JSON object with jsonrpc, method, params, and id fields. Responses return either a result or an error object.

The API is transport-agnostic, but most providers offer HTTPS for standard calls and WebSocket for subscriptions. OnFinality documents both transports and current plan-dependent limits on the /networks/eth page.

  • Mainnet chain ID: 1; Sepolia chain ID: 11155111. Never mix them when signing transactions.
  • Execution-layer JSON-RPC (eth_*) is separate from the Beacon consensus API, which serves validator and slot data via REST.
  • For testnet access, see the Sepolia guide at /rpc-assistant/sepolia-eth-rpc.

Core JSON-RPC Methods: eth_call, eth_getLogs, eth_sendRawTransaction, Receipts, and Gas Estimation

These methods cover most dApp workflows. Use eth_call to simulate a transaction without changing state; eth_getLogs to query event logs; eth_sendRawTransaction to broadcast a signed transaction; eth_getTransactionReceipt to confirm status and retrieve logs; and eth_estimateGas to plan gas before sending.

Always sign transactions locally before calling eth_sendRawTransaction. Never send a private key to an RPC endpoint.

  • eth_call: executes a read-only contract call at a specific block number or latest.
  • eth_getLogs: returns logs matching an address and optional topic filter, often used with block range pagination.
  • eth_sendRawTransaction: submits a raw, signed transaction; returns a transaction hash immediately.
  • eth_getTransactionReceipt: returns status (0x1 success), cumulative gas used, logs, and contract address after mining.
  • eth_estimateGas: returns an estimate, not a guarantee; add a buffer for complex interactions.

HTTP vs WebSocket: Choosing the Right Transport

HTTP is ideal for one-off reads and writes. Each request gets a single response and the connection can be reused. WebSocket maintains a persistent connection and pushes notifications, making it the right choice for real-time features.

  • Use HTTPS for user-initiated actions, balance checks, transaction submission, and batch requests.
  • Use WebSocket for eth_subscribe streams such as new block headers, filtered logs, and pending transactions.
  • Many production systems combine both: HTTP for user requests and WebSocket for background indexing or monitoring.
  • WebSocket connections require reconnect and resubscription logic; do not assume they stay open indefinitely.

WebSocket Subscription Workflows

WebSocket subscriptions use JSON-RPC eth_subscribe with a subscription name and optional filter. The server returns a subscription ID, then pushes eth_subscription notifications as events arrive.

Example subscription to new heads: ``json {"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]} ``

For logs, include an address and topics filter in params. For pending transactions, use newPendingTransactions, but note that mempool visibility depends on node configuration.

  • Handle reconnection by re-subscribing after a dropped WebSocket.
  • Use a unique id per request to match responses and notifications.
  • WebSocket availability and rate limits are plan-dependent; verify on /networks/eth.

Trace and Debug API Entry Points

Trace (trace_*) and Debug (debug_*) APIs are optional, often provider-specific entry points. They are not part of the core Ethereum JSON-RPC methods and may require archive nodes or special permissions. Do not confuse them with standard eth_* methods or with the Beacon consensus API.

Use Trace/Debug for internal transaction inspection, call tracing, state diffs, and storage analysis. Common methods include trace_transaction, trace_replayTransaction, debug_traceTransaction, and debug_traceCall.

  • Trace namespace is typically Parity/OpenEthereum style; Debug is Geth style. Availability varies.
  • These methods can be expensive and heavily rate-limited. Check current plan details and archive support on /networks/eth.
  • For most dApps, core methods like eth_call and eth_getTransactionReceipt are sufficient; add Trace/Debug only for analytics or debugging.

Minimal curl and JavaScript Examples

The following examples use placeholder endpoints. Replace YOUR_ETHEREUM_ENDPOINT with the HTTPS or WSS URL from the OnFinality network page.

curl to get the latest block number: ```bash curl -X POST https://YOUR_ETHEREUM_ENDPOINT \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' ```

JavaScript with ethers.js to read a contract symbol and latest block: ``javascript import { ethers } from "ethers"; const provider = new ethers.JsonRpcProvider("https://YOUR_ETHEREUM_ENDPOINT"); const blockNumber = await provider.getBlockNumber(); console.log("Latest block:", blockNumber); const contract = new ethers.Contract( "0x0000000000000000000000000000000000000000", // replace with contract address ["function symbol() view returns (string)"], provider ); const symbol = await contract.symbol(); console.log("Symbol:", symbol); ``

Always keep private keys in a secure signer, never in the RPC request.

Production Integration Checklist

For additional provider evaluation criteria, see /rpc-assistant/leading-ethereum-rpc-solutions-guide.

Next steps: Ethereum RPC Providers.

CriterionWhat to checkWhy it matters
Endpoint capabilitySupport for eth_call, eth_getLogs, eth_sendRawTransaction, receipts, and archive methods if needed.Missing methods break core dApp functions.
Rate limits and quotasCurrent plan RPS, daily caps, and WebSocket connection limits on /networks/eth.Prevents throttling during traffic spikes.
Transport setupHTTPS for request/response, WebSocket for subscriptions; implement retry logic.Ensures reliable user experience and real-time data.
Chain identityConfirm chain ID 1 for mainnet, 11155111 for Sepolia; never cross-sign.Avoids sending testnet transactions to mainnet or vice versa.
Gas handlingCall eth_estimateGas before sending; handle estimation failures and add buffer.Reduces stuck or failed transactions.
Archive availabilityWhether historical state queries are needed; verify archive support on /networks/eth.Full nodes may not serve old balances or logs.
Trace/Debug needsOnly enable if required; confirm availability and plan-specific limits.Avoid unnecessary cost and complexity.
Regional access and monitoringEndpoint regions, health checks, and usage dashboards. See /api-service for dedicated options.Lower latency and faster issue detection.

Frequently Asked Questions

Is the Ethereum blockchain API the same as Ethereum RPC?

Yes, the Ethereum blockchain API commonly refers to the JSON-RPC interface exposed by Ethereum execution clients. RPC and API are often used interchangeably for the eth_* method set.

Do I need archive node access for eth_call and eth_getLogs?

eth_call at latest works on full nodes, but historical calls or logs beyond a node's pruning window require archive access. Check the OnFinality Ethereum network page for archive availability.

Can I use WebSocket for everything instead of HTTP?

WebSocket is best for subscriptions; HTTP is simpler for one-off calls and often has lower overhead. Many production apps use both.

What is the difference between Trace and Debug APIs?

Both provide deeper execution details, but Trace is usually Parity-style (trace_*) and Debug is Geth-style (debug_*). They are not core methods and availability varies by provider and plan.

How do I avoid sending transactions to the wrong network?

Check the chain ID in your transaction: mainnet is 1, Sepolia is 11155111. Sign with a wallet configured for the intended network and verify the endpoint chain ID with eth_chainId.

What should I do if I hit rate limits?

Implement exponential backoff for HTTP 429 responses, reduce request frequency, batch calls where possible, and consider upgrading your plan or using a dedicated endpoint.

RPC Knowledge Base

Related RPC details

Never Worry about Infrastructure Again

OnFinality takes away the heavy lifting of DevOps so you can build smarter and faster.

Get Started