getLatestBlockhash - Solana
Example code for the getLatestBlockhash JSON-RPC method. Complete guide on how to use the getLatestBlockhash JSON-RPC method in the GetBlock Web3 documentation.
Parameters
Parameter
Type
Required
Description
Config Object
Field
Type
Required
Description
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "getLatestBlockhash",
"params": [{"commitment": "confirmed"}],
"id": "getblock.io"
}'const { Connection } = require('@solana/web3.js');
const connection = new Connection('https://go.getblock.io/<ACCESS-TOKEN>/', 'confirmed');
const latestBlockhash = await connection.getLatestBlockhash();
console.log(latestBlockhash.blockhash, latestBlockhash.lastValidBlockHeight);import requests
response = requests.post(
'https://go.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'getLatestBlockhash',
'params': [{"commitment": "confirmed"}],
'id': 'getblock.io'
}
)
print(response.json()['result'])Response
Response Parameters
Parameter
Type
Description
Value Object
Field
Type
Description
Use Cases
Error Handling
Error Code
Message
Description
Was this helpful?