DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

Optimism Endpoint: Chain Settings, Connection, and Debugging

When you search for "Optimism endpoint," you usually need one of two things: the exact chain settings to configure a wallet or dApp, or a reliable JSON-RPC URL for production traffic. This article gives you both, plus the failure modes that waste the most debugging time.

Quick recommendation: which Optimism endpoint should you use?

Before you copy a URL into your config, decide what the endpoint will do:

  • Prototyping or a hackathon: a public endpoint like https://optimism.api.onfinality.io/public is fine for a few requests. Public endpoints are rate-limited and may not support WebSocket, so they are not a production foundation.
  • A production dApp or backend: use a managed RPC provider with higher rate limits, WebSocket support, and archive data if you need historical state. OnFinality offers RPC endpoints for Optimism with HTTP and WebSocket transport.
  • Real-time subscriptions (pending transactions, log events): you need a WebSocket endpoint. Many free RPCs omit wss://, so check transport support before you build.
  • Heavy analytics or indexing: you may need archive data or trace_/debug_ methods. Not all providers expose these, so confirm method support in advance.

If you are unsure which tier fits, start with the public endpoint for a smoke test, then move to a dedicated or paid RPC plan once traffic grows. See RPC pricing for options.

Optimism network settings at a glance

OP Mainnet and OP Sepolia share the same Ethereum-compatible JSON-RPC interface, but the chain IDs and endpoints differ. Mixing them up is the most common configuration error.

Parameter OP Mainnet OP Sepolia
Network name OP Mainnet OP Sepolia Testnet
Chain ID 10 11155420
Native currency ETH Sepolia ETH
Block explorer https://optimistic.etherscan.io https://sepolia-optimism.etherscan.io
Public RPC URL https://optimism.api.onfinality.io/public https://optimism-sepolia.api.onfinality.io/public
WebSocket support Yes (via provider) Yes (via provider)

These values match the chain configuration used by OnFinality's Optimism network page and Optimism Sepolia page.

Connecting to an Optimism endpoint

Using curl

A basic JSON-RPC request to check the latest block number looks like this:

curl https://optimism.api.onfinality.io/public \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

The response should be a hex-encoded block number, for example {"jsonrpc":"2.0","result":"0x1345678","id":1}.

Using ethers.js

In a Node.js or browser environment, you can connect with ethers v6:

import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://optimism.api.onfinality.io/public');

const blockNumber = await provider.getBlockNumber();
console.log('Current block:', blockNumber);
Enter fullscreen mode Exit fullscreen mode

For WebSocket subscriptions, use WebSocketProvider instead:

import { WebSocketProvider } from 'ethers';

const wsProvider = new WebSocketProvider('wss://optimism.api.onfinality.io/public');

wsProvider.on('block', (blockNumber) => {
  console.log('New block:', blockNumber);
});
Enter fullscreen mode Exit fullscreen mode

Note: the public endpoint may not support WebSocket. For production WebSocket access, use a managed provider that explicitly supports wss://.

Adding Optimism to a wallet

If you need to add OP Mainnet to MetaMask or another wallet, use these settings:

  • Network name: OP Mainnet
  • RPC URL: https://optimism.api.onfinality.io/public
  • Chain ID: 10
  • Currency symbol: ETH
  • Block explorer URL: https://optimistic.etherscan.io

For OP Sepolia, use chain ID 11155420 and the Sepolia explorer URL.

Common JSON-RPC methods on Optimism

Optimism supports the standard Ethereum JSON-RPC methods, plus a few L2-specific ones. The most useful for day-to-day development:

  • eth_blockNumber – get the latest block
  • eth_getBalance – query an address balance
  • eth_call – execute a read-only contract call
  • eth_sendRawTransaction – broadcast a signed transaction
  • eth_getTransactionReceipt – check transaction status
  • eth_subscribe – WebSocket subscriptions for new heads or logs
  • eth_getLogs – fetch event logs for a contract

For L2-specific data, you may also use eth_getProof or eth_getStorageAt depending on your use case. Check the provider's method support if you need debug_ or trace_ methods for deeper debugging.

Debug path: what to do when your Optimism endpoint fails

Endpoint failures usually fall into one of these categories. Use this table to diagnose quickly:

Symptom Likely cause Fix
CONNECTION REFUSED or timeout Wrong URL or network down Verify the URL and check your network connection
429 Too Many Requests Rate limit exceeded Use a paid or dedicated endpoint, or add backoff
-32601 Method not found Method not supported by provider Check provider's method list; use a different provider if needed
-32000 or -32005 Node sync issue or limit reached Wait and retry, or use a provider with higher limits
UNKNOWN CHAIN in wallet Wrong chain ID Set chain ID to 10 (mainnet) or 11155420 (Sepolia)
WebSocket disconnects Unstable connection or provider limit Use a provider with dedicated WebSocket support

If you see -32616 on a WebSocket response, the payload is too large. Switch to a POST request for that call.

Optimism endpoint vs running your own node

Running an OP Mainnet node gives you full control, but it comes with operational overhead. You need to run an execution client and a consensus client, keep them in sync, and handle storage growth. For most teams, a managed RPC provider is more practical.

Consideration Managed RPC Self-hosted node
Setup time Minutes Days
Maintenance Provider handles it You handle upgrades and monitoring
Cost Predictable monthly fee Hardware + bandwidth + engineering time
Scalability Provider scales You must scale manually
Archive data Often available Requires extra storage

If you need low latency, high throughput, or archive data without the ops burden, a dedicated node from OnFinality might be the right fit. See dedicated node for details.

Choosing a provider for your Optimism endpoint

When evaluating an RPC provider, compare these factors:

  • Transport support: HTTP and WebSocket. Some providers only offer HTTP.
  • Rate limits: Free tiers are heavily rate-limited. Check the requests-per-second (RPS) for your workload.
  • Archive data: Needed for historical state queries. Not all providers offer it.
  • Method support: trace_ and debug_ are not universal.
  • Reliability: Look for historical uptime and response time data, but avoid providers that promise absolute guarantees.
  • Pricing model: Flat-rate vs. usage-based. Flat-rate is easier to budget for production.

OnFinality offers RPC endpoints for Optimism with HTTP and WebSocket, and you can compare plans on RPC pricing.

Key Takeaways

  • An Optimism endpoint is a JSON-RPC URL for OP Mainnet (chain ID 10) or OP Sepolia (chain ID 11155420).
  • Public endpoints are fine for testing but not for production. Use a managed provider for reliability and WebSocket support.
  • Always verify chain ID and transport support before integrating.
  • Common failures include rate limits, wrong chain ID, and missing WebSocket support. Use the debug table to diagnose quickly.
  • For production, evaluate providers on rate limits, archive data, method support, and pricing.

Frequently Asked Questions

What is the Optimism RPC endpoint?

The public RPC endpoint for OP Mainnet is https://optimism.api.onfinality.io/public. For OP Sepolia, use https://optimism-sepolia.api.onfinality.io/public. These are rate-limited and intended for development.

Does the Optimism endpoint support WebSocket?

OnFinality's Optimism endpoints support both HTTP and WebSocket transport. However, the public URL may not support WebSocket. For production WebSocket access, use a dedicated or paid endpoint.

How do I add Optimism to MetaMask?

Use the chain settings above: RPC URL, chain ID 10, symbol ETH, and explorer URL. For Sepolia, use chain ID 11155420.

What is the difference between OP Mainnet and OP Sepolia?

OP Mainnet is the production network with real ETH. OP Sepolia is a testnet with free Sepolia ETH for development. Chain IDs differ: 10 vs 11155420.

Why am I getting rate limited on the public endpoint?

Public endpoints have strict rate limits. For higher limits, use a paid RPC plan or a dedicated node.

Can I use the Optimism endpoint for archive data?

Not all endpoints provide archive data. Check with your provider. OnFinality offers archive data on certain plans; see RPC pricing for details.

Related resources

Originally published at OnFinality.

Top comments (0)