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

subscribe - Nervos

Example code for the subscribe JSON-RPC method. Complete guide on how to use subscribe JSON-RPC in GetBlock Web3 documentation.

Subscribes to a topic over WebSocket. Available topics: new_tip_header (new tip headers), new_tip_block (new tip blocks with transactions), new_transaction (new transactions entering the pool), proposed_transaction (transactions moved to proposed state), rejected_transaction (transactions rejected from the pool). Returns a subscription ID; events arrive as separate WebSocket messages.

WebSocket-only method. This method is part of the Subscription module and is only available over the WebSocket transport at wss://go.getblock.io/<ACCESS-TOKEN>/. It will not work via HTTP POST.

Parameters

Parameter
Type
Required
Description

topic

string

Yes

One of new_tip_header, new_tip_block, new_transaction, proposed_transaction, rejected_transaction

Request Example

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

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

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

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

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

Response Example

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

Response Parameters

Field
Type
Description

result

string

Subscription ID — used to match incoming notifications and to call unsubscribe

Use Cases

  • Real-time block notifications for indexers

  • Live wallet activity (subscribe to new_transaction filtered to your address)

  • Mempool monitoring dashboards

  • Detecting rejected transactions for RBF logic

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32601

Method not found

Method does not exist or is not enabled on this node

-32603

Internal error

Server-side error while processing the request

429

Too Many Requests

Rate limit exceeded for your plan

-32600

Invalid Request

subscribe was called over HTTP; use a WebSocket connection instead

-32602

Invalid topic

Topic string is not one of the supported topics

SDK Integration

Last updated

Was this helpful?