Skip to main content

getLatestBlockhash

Returns the latest blockhash

Common use cases
Transaction Construction Pre-FlightGet fresh blockhash immediately before building and sending transaction. Pattern: const { blockhash, lastValidBlockHeight } = await rpc.getLatestBlockhash({ commitment: 'confirmed' })
Transaction Expiration ValidationCheck current block height against lastValidBlockHeight to determine if transaction can still be submitted. Critical for retry logic and transaction monitoring.
Trading Bot Transaction BatchingRetrieve single blockhash to use across multiple transactions in atomic bundle. Ensures all transactions in bundle share same lifetime window.
Durable Nonce AlternativeSimple blockhash for short-lived transactions (vs. durable nonce for offline signing). Use case: Server-side transaction construction with immediate submission.
Finalized Commitment for Production SafetyUse getLatestBlockhash({ commitment: 'finalized' }) to avoid minority fork issues. Guarantees blockhash from canonical chain, preventing "blockhash not found" errors.

Parameters

config (object, optional)

Configuration object containing the following fields:

Fields:

  • commitment (string): The commitment describes how finalized a block is at that point in time. See Configuring State Commitment.
  • minContextSlot (number): The minimum slot that the request can be evaluated at

Request

curl https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getLatestBlockhash",
"params": [
{
"commitment": "processed"
}
]
}'
Network Selection

Replace mainnet with devnet in the URL to query devnet instead.

Response

{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 2792
},
"value": {
"blockhash": "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N",
"lastValidBlockHeight": 3090
}
},
"id": 1
}

Response Fields

blockhash (string)

A Hash as base-58 encoded string

lastValidBlockHeight (u64)

Last block height at which the blockhash will be valid

FAQ and Troubleshooting

Why do I get "Blockhash not found" error when simulating transactions?

Three causes: (1) Used processed/confirmed blockhash during minority fork - use finalized commitment; (2) Blockhash expired (~60 sec lifetime) - retrieve immediately before sending; (3) Network mismatch - verify wallet and RPC are on same network (devnet/mainnet).

What's the difference between lastValidBlockHeight and blockhash expiration?

lastValidBlockHeight is the absolute block height after which the blockhash becomes invalid. The cluster maintains a rolling window of ~150 blocks (~60 seconds) where blockhashes are valid. Compare current block height (from getBlockHeight) to lastValidBlockHeight to check transaction freshness.

When should I use finalized vs confirmed commitment?

Use finalized for production transactions to guarantee blockhash from canonical chain, avoiding minority fork issues. Use confirmed for development/testing when speed matters more than absolute safety. processed is rarely appropriate for getLatestBlockhash.

Why does getLatestBlockhash not work on my localnet?

This method was introduced in Solana v1.9 (August 2022). If running older version (≤v1.8), use deprecated getRecentBlockhash instead. In Agave 2.0+, getRecentBlockhash is removed entirely.

How long is a blockhash valid?

Approximately 60 seconds or ~150 blocks (400ms/block). The exact validity is determined by lastValidBlockHeight - current_block_height. Best practice: retrieve blockhash immediately before transaction construction to maximize valid submission window.

getBlockHeight
Returns current block height, used with lastValidBlockHeight to validate blockhash freshness before submission.

isBlockhashValid
Explicitly checks if a blockhash is still valid for transaction submission, useful for retry logic.

getFeeForMessage
Requires valid blockhash to calculate transaction fees, commonly called after getLatestBlockhash.

sendTransaction
Primary consumer of blockhash - transaction must include recent blockhash from getLatestBlockhash.

External Resources