Optimism
Ready to call this in production?
Free tier covers personal projects. Pay-as-you-go scales without a card.
Optimism
Free tier covers personal projects. Pay-as-you-go scales without a card.
eth_subscribe opens a push-based subscription over a persistent WebSocket connection to OP Mainnet, the OP Stack optimistic rollup that settles to Ethereum L1 and pays gas in ETH. Instead of repeatedly polling for changes, you register interest in an event stream — new block headers, matching logs, pending transactions, or sync status — and the node pushes eth_subscription notifications the moment events occur. On a fast L2 with roughly 2-second blocks this is the difference between near-instant updates and wasted round trips. Connect over WebSocket at https://optimism.therpc.io/YOUR_API_KEY (chain ID 10, 0xa) and you receive a hex subscription ID to correlate the incoming stream.
newHeads to drive real-time dashboards and block explorers that track OP Mainnet's ~2-second cadence without any polling loop.logs with an address/topics filter to react to events from a contract — for example Velodrome pool swaps or Synthetix events — the instant they are included in a block.newPendingTransactions to observe transactions entering the sequencer's mempool before they are confirmed.| # | Name | Type | Required | Description |
|---|---|---|---|---|
| 1 | subscriptionType | string | Yes | Subscription type: `newHeads` — new block headers; `logs` — matching event logs; `newPendingTransactions` — pending tx hashes; `syncing` — node sync status changes. |
| 2 | filter | object | No | Required only for `logs` subscriptions. Same filter shape as eth_newFilter: `address` and/or `topics`. |
| Type | Description |
|---|---|
| string | Hex subscription ID. Subsequent notifications arrive as `eth_subscription` messages with `params.subscription` matching this ID. |
Try it live in the Optimism playground.
| Code | Message | Cause |
|---|---|---|
-32602 | invalid argument | Unknown subscription type or malformed filter for a logs subscription. |
-32000 | notifications not supported | Method called over an HTTP connection instead of WebSocket. |
eth_subscribe over a plain HTTP transport returns a "notifications not supported" error.eth_getLogs over the missed block range.logs notifications can still carry removed: true entries on rare reorgs near the unsafe head; handle these explicitly and only treat finalized data as settled once it is anchored on Ethereum L1.Parameters
"newHeads" | "logs" | "newPendingTransactions" | "syncing"
Required only for `logs` subscriptions. Same filter shape as eth_newFilter: `address` and/or `topics`.