subscribe - Cosmos

Subscribes to events matching a Tendermint event query over the WebSocket endpoint. Matching events (new blocks, transactions) are then streamed to the connection.

Method

subscribe

Parameters

ParameterTypeDescription
querystringTendermint event query, e.g. "tm.event='NewBlock'"

Example

bashexport COSMOS_TM=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

# JSON-RPC over WebSocket (append /websocket to the endpoint)
wscat -c "wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/websocket" \
  -x '{"jsonrpc": "2.0", "id": "getblock.io", "method": "subscribe", "params": {"query": "tm.event='NewBlock'"}}'

Response

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

Response Fields

FieldTypeDescription
resultobjectEmpty on subscribe; matching events arrive as subsequent messages

Use Cases

  • Live blocks: Stream NewBlock events
  • Tx streams: Subscribe to transactions matching a query

Error Handling

ErrorMessageDescription
-32600 / Invalid requestInvalid requestThe JSON-RPC envelope was malformed
-32602 / Invalid paramsInvalid paramsA parameter was missing or of the wrong type
403 / RBAC: access deniedAccess deniedThe GetBlock access token is missing or incorrect