Logo
RPC Assistant

Ethereum API: Methods, Endpoints, and How to Start Building

Summary

The Ethereum API lets your application interact with the Ethereum blockchain via JSON-RPC. This article covers common methods, how to connect to endpoints, and criteria for choosing an RPC provider for production apps.

Ethereum API decision checklist

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

CriterionWhat to checkWhy it matters
API method coverageDoes 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 typePublic, free-tier, or dedicated private endpoint?Public endpoints have rate limits and lower reliability.
Network supportMainnet, testnets (Sepolia, Holesky), or both?Testnets are essential for staging.
WebSocket supportDoes the provider offer WSS for real-time subscriptions?Needed for event listening.
Archive dataDo you need access to historical state?Requires an archive node.
Rate limitsWhat are the request-per-second and daily call limits?Production apps need predictable limits.
Latency and uptimeCheck historical performance and SLAs (if promised).High latency can break user experience.
Pricing modelPay-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:

MethodParametersDescription
eth_blockNumbernoneReturns the latest block number.
eth_getBalanceaddress, blockReturns the balance of an address.
eth_getTransactionCountaddress, blockReturns the nonce of an address.
eth_calltransaction, blockExecutes a read-only contract call.
eth_sendRawTransactionsigned transactionSubmits a signed transaction.
eth_getLogsfilter objectRetrieves event logs matching a filter.
eth_gasPricenoneReturns the current gas price.
eth_estimateGastransactionEstimates 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

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);

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.

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