eth_subscribe

网络: Arbitrum One · 主网 · Chain ID 42161(0xa4b1)

计为 1 个 Request。 计费规则见 Request Counting。

eth_subscribe 只能通过 WSS endpoint 使用。链路开启 WSS 时,可订阅 newHeads、logs 等实时事件。

参数

  1. String - 订阅类型,如 newHeads、logs、newPendingTransactions。
  2. Object - 可选过滤对象,例如 logs 订阅的地址和 topics。

请求

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

代码示例

const ws = new WebSocket("wss://arbitrum-one-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)); };

在线试用