githubEdit

eth_unsubscribe - Celo

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

This method cancels an existing subscription on the Celo network. This should be called to clean up subscriptions when they are no longer needed.

Parameters

Parameter
Type
Required
Description

subscriptionId

string

Yes

Subscription ID to cancel

Request Example

websocket.js
const WebSocket = require('ws');

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

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

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

Response Example

Response Definition

Field
Type
Description

result

boolean

true if successfully unsubscribed

Use Cases

  • Clean up unused subscriptions

  • Manage connection resources

  • Implement proper lifecycle management

Error Handling

Error Code
Description

-32602

Invalid subscription ID

-32603

Internal error

Last updated

Was this helpful?