Access current block height inside a custom transaction

Is it possible to get the current/last block height and maybe even the complete last block inside a transaction?
Readonly will be enough :wink: but there is no block statestore and no configured block storage component afaik available inside the transaction class.

Hi Moosty

Unfortunately, this is not possible to access the latest block through statestore.
The reason for that is that the latest block is a dynamic piece of data which is not ideal for a custom transaction that needs to be deterministic across all nodes. A block might be received later in other nodes which means they have another latest block, invalidating your transaction.

Although, you can create a custom module for listening to new blocks. The event to listen to is app:updateState or the block events. Still, we do not recommend this solution.

Hope this answer helps you!

1 Like