DEV Community

Zhuoxin Sun
Zhuoxin Sun

Posted on • Originally published at onfinality.io

Ethereum API Reference: Methods, Endpoints, and Provider Selection

Ethereum API decision checklist

Before you start building with the Ethereum API, consider these decision points:

Criterion What to check Why it matters
API method coverage Does your use case need only standard JSON-RPC or also custom endpoints (e.g., debug, trace)? Some applications require archive data or trace calls.
Endpoint type Public, free-tier, or dedicated private endpoint? Public endpoints have rate limits and lower reliability.
Network support Mainnet, testnets (Sepolia, Holesky), or both? Testnets are essential for staging.
WebSocket support Does the provider offer WSS for real-time subscriptions? Needed for event listening.
Archive data Do you need access to historical state? Requires an archive node.
Rate limits What are the request-per-second and daily call limits? Production apps need predictable limits.
Latency and uptime Check historical performance and SLAs (if promised). High latency can break user experience.
Pricing model Pay-as-you-go, monthly subscription, or custom? Cost scales with usage.

What is the Ethereum API?

The Ethereum API is a set of JSON-RPC methods that allow applications to communicate with an Ethereum node. Every Ethereum client (e.g., Geth, Erigon, Nethermind) exposes these methods over HTTP, WebSocket, or IPC. The API enables reading blockchain data (balances, transactions, logs), writing state (sending transactions), and interacting with smart contracts.

Common Ethereum API methods

Here are the most frequently used JSON-RPC methods:

Method Parameters Description
eth_blockNumber none Returns the latest block number.
eth_getBalance address, block Returns the balance of an address.
eth_getTransactionCount address, block Returns the nonce of an address.
eth_call transaction, block Executes a read-only contract call.
eth_sendRawTransaction signed transaction Submits a signed transaction.
eth_getLogs filter object Retrieves event logs matching a filter.
eth_gasPrice none Returns the current gas price.
eth_estimateGas transaction Estimates gas for a transaction.

For a complete list, see the official Ethereum JSON-RPC specification.

How to connect to an Ethereum API

You need an endpoint URL. Here's an example using curl to get the latest block number from a public endpoint (replace with your provider's URL):

curl -X POST -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
  https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
Enter fullscreen mode Exit fullscreen mode

Using a library like viem in JavaScript:

import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';

const client = createPublicClient({
  chain: mainnet,
  transport: http('https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY'),
});

const blockNumber = await client.getBlockNumber();
console.log('Block number:', blockNumber);
Enter fullscreen mode Exit fullscreen mode

Public vs. private endpoints

  • Public endpoints (free, rate-limited) are suitable for testing and low-volume use.
  • Free-tier endpoints from providers offer higher limits than public ones but still have caps.
  • Dedicated nodes give you exclusive access, clear rate limits, and full control. They are ideal for production.

For production apps, a dedicated node or a managed RPC service with consistent performance is recommended. OnFinality provides both shared and dedicated node infrastructure across multiple chains, including Ethereum.

How to choose an Ethereum API provider

When evaluating providers, consider:

  • Network support: Does the provider support Ethereum mainnet and the testnets you need (Sepolia, Holesky)?
  • Method coverage: Some providers restrict debug or trace methods. If you need archive data, confirm archive node availability.
  • WebSocket (WSS) support: Essential for real-time subscriptions (e.g., pending transactions, new blocks).
  • Pricing: Compare RPC pricing across providers. Look for transparent, predictable fees.
  • Uptime and latency: Check historical status. While no provider can guarantee 100% uptime, choose one with a strong track record.
  • Developer experience: Look for easy API key setup, dashboard, and documentation.

For a deeper dive, see our guide to choosing an RPC provider.

Common pitfalls and troubleshooting

  • Rate limits: If you get 429 Too Many Requests, consider upgrading your plan or adding load balancing.
  • Nonce errors: When sending transactions, ensure you use the correct nonce (see our nonce guide).
  • Gas estimation failures: Use eth_estimateGas before sending. For complex contracts, increase the gas limit.
  • Connection timeouts: For high-volume apps, use WebSocket instead of HTTP for persistent connections.
  • Archive node missing: If you get errors when querying historical state, switch to an archive endpoint.

Key Takeaways

  • The Ethereum API is standard JSON-RPC. Any compliant client works across providers.
  • Choose endpoints based on your workload: public for testing, free-tier for small apps, dedicated for production.
  • Always test on testnets before mainnet deploys.
  • Monitor your API usage and latency to avoid surprises.
  • OnFinality offers Ethereum RPC endpoints with flexible plans. Check the list of supported networks and pricing to get started.

Frequently Asked Questions

Q: What is the difference between the Ethereum API and an RPC endpoint?
A: The Ethereum API refers to the JSON-RPC methods. An RPC endpoint is the URL where you send requests. They are often used interchangeably.

Q: Can I use the same API key for mainnet and testnets?
A: Most providers give separate endpoints per network but use the same API key. Some require you to create separate projects.

Q: Do I need a dedicated node for Ethereum?
A: Not always. For low-traffic apps, a managed service's shared endpoint may suffice. For high throughput, low latency, or custom configurations, a dedicated node is better.

Q: How do I get archive data?
A: Choose a provider that explicitly offers archive endpoints. OnFinality provides archive node access on request.

Q: What is the best library to use with the Ethereum API?
A: Popular options include ethers.js, web3.js, and viem. The choice depends on your language and preference. All abstract JSON-RPC calls.

Related resources

Originally published at OnFinality.

Top comments (0)