Parameters

config
object

Response

result
object

Code Examples

Basic Request

curl http://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLatestBlockhash",
  "params": [
    {"commitment": "processed"}
  ]
}'

Using web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('http://rpc.orbitflare.com');
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
console.log(blockhash, lastValidBlockHeight);

Using Python

from solana.rpc.api import Client

client = Client("http://rpc.orbitflare.com")
response = client.get_latest_blockhash()
print(response)

Notes

  1. This method returns the latest blockhash and how long it will be valid for
  2. Replaces the deprecated getRecentBlockhash method
  3. The blockhash is used for transaction processing and deduplication
  4. The blockhash is valid until the specified lastValidBlockHeight is reached
  5. Different commitment levels can be specified for the response

Best Practices

  1. Use blockhash for transaction submission and signing
  2. Monitor lastValidBlockHeight to determine blockhash validity
  3. Refresh blockhash if lastValidBlockHeight is reached or exceeded
  4. Handle network errors and retry when appropriate
  5. Cache the blockhash for multiple transactions within its validity period