Learn getLatestBlockhash use cases, code examples, request parameters, response structure, and tips.
getLatestBlockhash
RPC method is essential for preparing and sending transactions on the Solana network. It retrieves the most recent blockhash processed by the node, along with the last block height at which this blockhash will remain valid. For more details on how to effectively use blockhashes and ensure your transactions land, refer to our comprehensive guide.
Every transaction on Solana must reference a recent blockhash. This mechanism helps prevent certain types of attacks, such as transaction replay on a forked chain.
Version Note: This method is available in solana-core
v1.9 or newer. For nodes running solana-core
v1.8 or older, use the getRecentBlockhash
method instead.
lastValidBlockHeight
to understand how long a transaction referencing the fetched blockhash can be expected to remain valid.simulateTransaction
can do this implicitly, applications might fetch a blockhash to manually prepare a transaction for simulation.commitment
(string, optional): Specifies the commitment level for the query. If omitted, the node’s default commitment is used. For transactions, it’s common to use confirmed
or finalized
to ensure the blockhash is from a reasonably stable part of the chain.minContextSlot
(integer, optional): The minimum slot that the request can be evaluated at. This ensures the query is made against a ledger state that has processed up to at least this slot.result
field of the JSON-RPC response will be an RpcResponse
object. The value
field within this object contains:
blockhash
(string): A base-58 encoded string representing the latest blockhash.lastValidBlockHeight
(u64): The block height at which the blockhash
will expire. A transaction citing this blockhash
is valid until the network reaches this lastValidBlockHeight
.context
object with the slot
at which the information was retrieved.
confirmed
commitment.
lastValidBlockHeight
is passed. Always fetch a fresh blockhash if considerable time has passed since the last one was obtained.finalized
commitment provides the strongest guarantee that the blockhash is from the main chain fork, but it may be slightly older. confirmed
offers a good balance. Learn more about commitment levels for detailed information.lastValidBlockHeight
is passed, you must re-sign it with a new, more recent blockhash and resubmit.getLatestBlockhash
effectively, a cornerstone for interacting with the Solana network through transactions.