Observing new data
Aside from querying data, you can also observe new data as its inserted inside the chain itself. In this way, you will be notified as soon as a transaction is properly executed without having to constantly polling the chain state by yourself.
All the live data observation is done though the usage of a websocket. The endpoint of such websocket is the following:
In order to subscribe to specific events, you will need to send one or more messages to the websocket once you opened a connection to it. Such messages need to contain the following JSON object and must be string encoded:
"query": "tm.event='eventCategory' AND eventType.eventAttribute='attributeValue'"
query field can have the following values:
tm.event='NewBlock'if you want to observe each new block that is created (even empty ones);
tm.event='Tx'if you want to subscribe to all new transactions;
message.action='<action>'if you want to subscribe to events emitted when a specific message is sent to the chain. In this case, please refer to the
Message actionsection on each transaction message specification page to know what is the type associated to each message.
Please note that if you want to subscribe to multiple events you will need to send multiple query messages upon connecting to the websocket.