The /chain/infoGET endpoint returns the current chain height and the latest finalization height.
Comparing both values shows how far behind the finalized state is from the chain tip, which is useful for
applications that need to confirm transactions are irreversible.
This tutorial shows how to poll chain state in a loop and display how long ago each height last changed.
On each iteration, the code sends a GET request to the /chain/infoGET endpoint.
The response contains:
height: The current chain height (the latest block known to the node).
latestFinalizedBlock: An object with details about the most recently finalized block, including:
height: The finalized block height.
finalizationEpoch: The finalization epoch number.
finalizationPoint: The finalization point within the epoch.
hash: The hash of the finalized block.
Prove That the Block Is Part of the Blockchain
Finalization only proves that the network has agreed on a specific block hash.
To fully verify finality, it should also be checked that this hash actually belongs to the current
blockchain.
This can be done by retrieving blocks around the reported finalized height and confirming that one of them
contains the finalized hash in its header.
The chain height increases each time a new block is produced (approximately every 30 seconds).
The finalized height lags behind the chain tip because a block is typically finalized 10 to 20 minutes after it is
produced.
When a finalization round completes, the finalized height jumps forward by many blocks at once rather than
advancing one block at a time.
See the Consensus textbook section for details on how
voting nodes drive this process.
To show how long ago each height last changed, the code stores the previous values and their timestamps.
When a height differs from the previous value, the timestamp is updated to the current time.
Until a change is observed, the timestamp remains unset and the output displays - instead of a number.
Once a change occurs, the counter starts from 0s ago and increments each second until the next change.
Before any change (lines 2-4): Both counters show - because no change has been observed yet.
A new block confirms (line 5): The chain height advances from 3,159,411 to 3,159,412 and its change counter
starts from 0s.
A finalization round completes (line 7): The finalized height jumps 23 blocks from 3,159,388 to 3,159,411,
and its change counter starts from 0s.
The gap between the chain height and the finalized height is normal.
A transaction included in a block at the chain tip is confirmed but not yet irreversible.
Once the finalized height reaches or exceeds that block, the transaction is guaranteed to remain in the chain.