subscribe - Cosmos

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

Subscribes to events matching a Tendermint event query over WebSocket. Use queries like tm.event='NewBlock', tm.event='Tx', or transfer.recipient='cosmos1...'. Returns a subscription that streams matching events as separate WebSocket messages.

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 such as wscat, the @cosmjs/tendermint-rpc WebSocketClient, or Python's websockets library.

Parameters

Parameter
Type
Required
Description

query

string

Yes

Tendermint event query string

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": "subscribe", "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 — streamed events arrive as separate WebSocket messages

Use Cases

  • Real-time block notifications (tm.event='NewBlock')

  • Live transaction streaming (tm.event='Tx')

  • Per-account activity feeds (transfer.recipient='cosmos1...')

  • IBC packet flow monitoring

  • Governance event tracking

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

-32603

Subscription limit exceeded

Each WebSocket connection has a maximum subscription count (typically 5)

-32602

Invalid query

Query string is malformed or references unknown event types

SDK Integration

Last updated

Was this helpful?