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

eth_unsubscribe - BSC

Example code for the eth_unsubscribe JSON RPC method. Сomplete guide on how to use eth_unsubscribe JSON RPC in GetBlock Web3 documentation.

This method cancels a WebSocket subscription

This method is available only over WebSocket connections.

Parameters

Parameter
Type
Required
Description

subscriptionId

string

Yes

Subscription ID to cancel

Request Example

cURL (wscat)
# This method requires WebSocket connection
wscat -c wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

> {"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0x1"],"id":"getblock.io"}
JavaScript (ws)
const WebSocket = require('ws');

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

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

ws.on('message', (data) => {
    console.log(JSON.parse(data));
});
Python (websockets)
import asyncio
import websockets
import json

async def unsubscribe():
    uri = "wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
    async with websockets.connect(uri) as ws:
        payload = {
            "jsonrpc": "2.0",
            "method": "eth_unsubscribe",
            "params": ["0x1"],
            "id": "getblock.io"
        }
        await ws.send(json.dumps(payload))
        response = await ws.recv()
        print(json.loads(response))

asyncio.run(unsubscribe())

Response Example

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

Response Parameters

Parameter
Type
Description

result

boolean

Unsubscribe success status

Use Cases

  • Cancel block subscriptions

  • Stop log monitoring

  • Clean up WebSocket connections

  • Resource management

Error Handling

Error Code
Description

-32602

Invalid subscription ID

-32603

Internal error

SDK Integration

Last updated

Was this helpful?