unsubscribe - Cosmos

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

Cancels a specific subscription on the current WebSocket connection. Specify the same query used in the original subscribe call.

WebSocket-only method. This method is only available over the WebSocket transport at wss://go.getblock.io/<ACCESS-TOKEN>/websocket. It will not work via HTTP POST. Use a WebSocket client like wscat, the @cosmjs/tendermint-rpc WebsocketClient, or Python's websockets library.

Parameters

Parameter
Type
Required
Description

query

string

Yes

The query string of the subscription to cancel

Request Example

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

# Then send:
{"jsonrpc": "2.0", "method": "unsubscribe", "params": {"query": "tm.event='NewBlock'"}, "id": "getblock.io"}

Response Example

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

Response Parameters

Field
Type
Description

result

object

Empty object on success

Use Cases

  • Stopping a specific event stream without dropping the WebSocket connection

  • Cleanup when a feature/view that subscribed is no longer needed

Error Handling

Status Code
Error Message
Cause

404

Not Found

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32603

Internal error

Server-side error while processing the request

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Last updated

Was this helpful?