eth_subscribe

Network: Polygon · Mainnet · Chain ID 137 (0x89)

Counts as 1 request. See Request Counting.

eth_subscribe is available over WSS endpoints only. It creates a live subscription for event streams such as new heads or logs when the chain route has WSS enabled.

Parameters

  1. String - Subscription type, such as newHeads, logs, or newPendingTransactions.
  2. Object - Optional filter object for subscription types such as logs.

Request

{ "jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"], "id": 1 }

Code Examples

const ws = new WebSocket("wss://polygon-bor-rpc.blockreq.com/v1/rpc/public"); ws.onopen = () => { ws.send(JSON.stringify({ "jsonrpc": "2.0", "method": "eth_subscribe", "params": [ "newHeads" ], "id": 1 })); }; ws.onmessage = (event) => { console.log(JSON.parse(event.data)); };

Try It