For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_subscribe - Robinhood

Example code for the eth_subscribe JSON-RPC method. Complete guide to using the eth_subscribe JSON-RPC method in GetBlock.io Web3 documentation.

Subscribes to events over WebSocket. Returns a subscription ID; matching events arrive as separate WebSocket messages with that ID. Supported subscription types: newHeads (new block headers), logs (filtered event logs), newPendingTransactions (pending tx hashes), syncing (sync status changes). With Robinhood Chain's 100ms block cadence, newHeads fires very frequently — ensure your consumer can handle the throughput.

Parameters

Parameter
Type
Required
Description

type

string

Yes

Subscription type — one of newHeads, logs, newPendingTransactions, syncing

filter

object

No

For logs subscriptions: filter object with address and topics

Request Example

# WebSocket-only method. Use wscat (or similar) to connect first:
wscat -c 'wss://shared.us-east-1.getblock.io/<ACCESS-TOKEN>/'

# Then send:
{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"], "id": "getblock.io"}
import WebSocket from 'ws';

const ws = new WebSocket('wss://shared.us-east-1.getblock.io/<ACCESS-TOKEN>/');

ws.on('open', () => {
    ws.send(JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_subscribe",
    "params": [
        "newHeads"
    ],
    "id": "getblock.io"
}));
});

ws.on('message', (data) => {
    console.log(JSON.parse(data.toString()));
});

Response Example

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0xcd0c3e8af590364c09d0fa6a1210faf5"
}

Response Parameters

Field
Type
Description

result

string

Subscription ID — match incoming notifications by this and use to call eth_unsubscribe

Use Cases

  • Real-time block notifications for indexers and explorers

  • Live Stock Token transfer tracking (subscribe to logs filtered to Stock Token contracts)

  • Mempool monitoring (newPendingTransactions)

  • Detecting sync state changes

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32603

Internal error

Server-side error while processing the request

429

Too Many Requests

Rate limit exceeded for your plan

-32600

Invalid Request

eth_subscribe called over HTTP; use WebSocket

-32602

Invalid subscription type

Type is not one of the four supported

SDK Integration

Last updated

Was this helpful?