eth_unsubscribe - Celo

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

ParameterTypeRequiredDescription
subscriptionIdstringYesSubscription ID to cancel

Request Example

websocket.js

javascriptconst 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',
    id: 1,
    method: 'eth_unsubscribe',
    params: ['0x9cef478923ff08bf67fde6c64013158d']
  }));
});

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

unsubscribe.py

pythonimport 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:
        await ws.send(json.dumps({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "eth_unsubscribe",
            "params": ["0x9cef478923ff08bf67fde6c64013158d"]
        }))
        
        response = await ws.recv()
        print(json.loads(response))

asyncio.run(unsubscribe())

Response Example

response.json

json{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}

Response Definition

FieldTypeDescription
resultbooleantrue if successfully unsubscribed

Use Cases

  • Clean up unused subscriptions
  • Manage connection resources
  • Implement proper lifecycle management

Error Handling

Error CodeDescription
-32602Invalid subscription ID
-32603Internal error