Logo
RPC Assistant

Optimism Endpoint: Chain Settings, Connection, and Debugging

Summary

An Optimism endpoint is a JSON-RPC URL that lets your dApp or backend read and write data on OP Mainnet or OP Sepolia. This article covers the exact chain settings, how to connect via curl or ethers.js, and how to debug common endpoint failures.

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.

ParameterOP MainnetOP Sepolia
Network nameOP MainnetOP Sepolia Testnet
Chain ID1011155420
Native currencyETHSepolia ETH
Block explorerhttps://optimistic.etherscan.iohttps://sepolia-optimism.etherscan.io
Public RPC URLhttps://optimism.api.onfinality.io/publichttps://optimism-sepolia.api.onfinality.io/public
WebSocket supportYes (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}'

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

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

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:

SymptomLikely causeFix
CONNECTION REFUSED or timeoutWrong URL or network downVerify the URL and check your network connection
429 Too Many RequestsRate limit exceededUse a paid or dedicated endpoint, or add backoff
-32601 Method not foundMethod not supported by providerCheck provider's method list; use a different provider if needed
-32000 or -32005Node sync issue or limit reachedWait and retry, or use a provider with higher limits
UNKNOWN CHAIN in walletWrong chain IDSet chain ID to 10 (mainnet) or 11155420 (Sepolia)
WebSocket disconnectsUnstable connection or provider limitUse 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.

ConsiderationManaged RPCSelf-hosted node
Setup timeMinutesDays
MaintenanceProvider handles itYou handle upgrades and monitoring
CostPredictable monthly feeHardware + bandwidth + engineering time
ScalabilityProvider scalesYou must scale manually
Archive dataOften availableRequires 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.

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