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

unsubscribe - Nervos

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

Cancels an existing subscription. Pass the subscription ID returned by subscribe.

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

subscription_id

string

Yes

Subscription ID returned by subscribe

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": "unsubscribe", "params": ["0xf1"], "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": "unsubscribe",
    "params": [
        "0xf1"
    ],
    "id": "getblock.io"
}));
});

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

Response Example

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

Response Parameters

Field
Type
Description

result

boolean

true if the subscription was cancelled, false if no such subscription existed

Use Cases

  • Stopping a live feed when the user navigates away

  • Cleanup in WebSocket-based microservices

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

unsubscribe was called over HTTP; use a WebSocket connection instead

SDK Integration

Last updated

Was this helpful?