getLatestBlockhash
method returns the latest block hash that’s usable for a new transaction.
This method provides the latest block hash, which is required for creating a new transaction. It is useful for creating new transactions that are valid for inclusion in the ledger.
See also Understanding the difference between blocks and slots on Solana.
slot
— the slot number; note slots and blocks are different entities.blockhash
— the hash of the block that’s produced in the slot number returned.lastValidBlockHeight
— the block (not slot!) height number until which the transaction is considered valid and after which it will expire. The lastValidBlockHeight
is always the current block (again, not slot!) number plus 150 blocks. See the example below for a walkthrough explanation.getLatestBlockhash
is to create new transactions that are valid for inclusion in the ledger. This can be useful for wallets or other applications that need to create new transactions. A pending transaction is considered valid to be committed to the chain for 150 blocks before it expires and gets dropped by nodes.
311118891
289445888
getLatestBlockhash
call that we are describing here:
"slot": 311115149
and "lastValidBlockHeight": 289442306
are about 22 million blocks apart.
If you are learning the Solana inner workings and check block 289442306 in the explorer, you will see that the block until which your pending transaction is supposed to stay valid is about 4 months in the past from the time of the call. How is that possible?
A transaction lives in the pool of pending transactions before it gets picked up by a validator for 150 blocks (not slots!) before it gets dropped.
So when doing a getLatestBlockheight
call, you get the lastValidBlockHeight
value that is determined by the current block height (current latest block at the time of the call, and not the slot height) + 150 blocks.
For our example, let’s do a getBlock call, the naming of which confuses things even further as you actually need to provide the slot number as a value in the getBlock
call:
"params": [311115149
"blockHeight": 289442156
289442156 - 289442306 = 150
. So this checks out.
You can get the current block (not slot!) height with the getBlockHeight call.
And you can get the current slot height with the getSlot call.
So, to it all sum up:
Latest blockhash details
The response is of type object
.