github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/docs/core/subscription.md (about)

     1  ---
     2  order: 7
     3  ---
     4  
     5  # Subscribing to events via Websocket
     6  
     7  CometBFT emits different events, which you can subscribe to via
     8  [Websocket](https://en.wikipedia.org/wiki/WebSocket). This can be useful
     9  for third-party applications (for analysis) or for inspecting state.
    10  
    11  [List of events](https://godoc.org/github.com/cometbft/cometbft/types#pkg-constants)
    12  
    13  To connect to a node via websocket from the CLI, you can use a tool such as
    14  [wscat](https://github.com/websockets/wscat) and run:
    15  
    16  ```sh
    17  wscat -c ws://127.0.0.1:26657/websocket
    18  ```
    19  
    20  NOTE: If your node's RPC endpoint is TLS-enabled, utilize the scheme `wss` instead of `ws`.
    21  
    22  You can subscribe to any of the events above by calling the `subscribe` RPC
    23  method via Websocket along with a valid query.
    24  
    25  ```json
    26  {
    27      "jsonrpc": "2.0",
    28      "method": "subscribe",
    29      "id": 0,
    30      "params": {
    31          "query": "tm.event='NewBlock'"
    32      }
    33  }
    34  ```
    35  
    36  Check out [API docs](https://docs.cometbft.com/v0.34/rpc/) for
    37  more information on query syntax and other options.
    38  
    39  You can also use tags, given you had included them into DeliverTx
    40  response, to query transaction results. See [Indexing
    41  transactions](./indexing-transactions.md) for details.
    42  
    43  ## ValidatorSetUpdates
    44  
    45  When validator set changes, ValidatorSetUpdates event is published. The
    46  event carries a list of pubkey/power pairs. The list is the same
    47  CometBFT receives from ABCI application (see [EndBlock
    48  section](https://github.com/cometbft/cometbft/blob/v0.34.x/spec/abci/abci++_methods.md#endblock) in
    49  the ABCI spec).
    50  
    51  Response:
    52  
    53  ```json
    54  {
    55      "jsonrpc": "2.0",
    56      "id": 0,
    57      "result": {
    58          "query": "tm.event='ValidatorSetUpdates'",
    59          "data": {
    60              "type": "tendermint/event/ValidatorSetUpdates",
    61              "value": {
    62                "validator_updates": [
    63                  {
    64                    "address": "09EAD022FD25DE3A02E64B0FE9610B1417183EE4",
    65                    "pub_key": {
    66                      "type": "tendermint/PubKeyEd25519",
    67                      "value": "ww0z4WaZ0Xg+YI10w43wTWbBmM3dpVza4mmSQYsd0ck="
    68                    },
    69                    "voting_power": "10",
    70                    "proposer_priority": "0"
    71                  }
    72                ]
    73              }
    74          }
    75      }
    76  }
    77  ```