Parameters

blockhash
string
required

The blockhash to validate (base-58 encoded)

config
object

Configuration object containing:

commitment
string

Commitment level (processed, confirmed, finalized)

minContextSlot
number

The minimum slot that the request can be evaluated at

Response

result
boolean

Whether the blockhash is still valid (true) or not (false)

Code Examples

Basic Request

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

Using web3.js

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

const connection = new Connection('https://rpc.orbitflare.com');

// Check if blockhash is valid
const isValid = await connection.isBlockhashValid('J7rBdM6AecPDEZp8aPq5tPmsPzPhQG4HD6YtAcQBDfJj');
console.log('Is blockhash valid:', isValid);

// Check blockhash validity with analysis
async function checkBlockhashValidityWithAnalysis(
  blockhash: string,
  config: { 
    commitment?: string;
    minContextSlot?: number;
  }
) {
  const isValid = await connection.isBlockhashValid(blockhash, config);
  
  return {
    blockhash,
    validity: {
      isValid,
      checkedAt: Date.now()
    },
    config: {
      commitment: config.commitment,
      minContextSlot: config.minContextSlot
    }
  };
}

Notes

  1. Returns whether a blockhash is still valid
  2. Blockhashes expire after a certain number of slots
  3. The response is immediate as it reads from the current state
  4. Invalid blockhashes cannot be used in transactions
  5. The blockhash must be base-58 encoded

Best Practices

  1. Use appropriate commitment level based on your needs
  2. Cache results when appropriate to reduce RPC load
  3. Check blockhash validity before sending transactions
  4. Consider using websocket subscription for real-time updates
  5. Handle network errors and retry when appropriate

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32602Invalid paramsCheck the blockhash format
-32007Blockhash not foundThe blockhash has expired or is invalid

Use Cases

  1. Blockhash Validation

    interface BlockhashValidation {
      blockhash: string;
      validity: {
        isValid: boolean;
        checkedAt: number;
      };
      config: {
        commitment?: string;
        minContextSlot?: number;
      };
    }
    
    class BlockhashValidator {
      async validateBlockhash(
        blockhash: string,
        config: { 
          commitment?: string;
          minContextSlot?: number;
        }
      ): Promise<BlockhashValidation> {
        const isValid = await connection.isBlockhashValid(blockhash, config);
        
        return {
          blockhash,
          validity: {
            isValid,
            checkedAt: Date.now()
          },
          config: {
            commitment: config.commitment,
            minContextSlot: config.minContextSlot
          }
        };
      }
    }
    
  2. Blockhash Monitoring

    interface BlockhashStatus {
      blockhash: string;
      status: {
        isValid: boolean;
        lastChecked: number;
        checkCount: number;
      };
      history: Array<{
        timestamp: number;
        isValid: boolean;
      }>;
    }
    
    class BlockhashMonitor {
      private statuses: Map<string, BlockhashStatus> = new Map();
      
      async monitorBlockhash(
        blockhash: string,
        config: { 
          commitment?: string;
          minContextSlot?: number;
        }
      ): Promise<BlockhashStatus> {
        const isValid = await connection.isBlockhashValid(blockhash, config);
        const now = Date.now();
        
        let status = this.statuses.get(blockhash);
        if (!status) {
          status = {
            blockhash,
            status: {
              isValid,
              lastChecked: now,
              checkCount: 1
            },
            history: [{
              timestamp: now,
              isValid
            }]
          };
        } else {
          status.status.isValid = isValid;
          status.status.lastChecked = now;
          status.status.checkCount++;
          status.history.push({
            timestamp: now,
            isValid
          });
        }
        
        this.statuses.set(blockhash, status);
        return status;
      }
    }
    
  3. Transaction Planning

    interface TransactionPlan {
      blockhash: string;
      validity: {
        isValid: boolean;
        checkedAt: number;
      };
      recommendations: Array<{
        type: 'proceed' | 'retry' | 'abort';
        reason: string;
      }>;
      metadata: {
        timestamp: number;
      };
    }
    
    class TransactionPlanner {
      private readonly maxRetries = 3;
      private readonly validityCheckInterval = 1000; // 1 second
      
      async planTransaction(
        blockhash: string,
        config: { 
          commitment?: string;
          minContextSlot?: number;
        }
      ): Promise<TransactionPlan> {
        const isValid = await connection.isBlockhashValid(blockhash, config);
        const now = Date.now();
        
        const recommendations: Array<{
          type: 'proceed' | 'retry' | 'abort';
          reason: string;
        }> = [];
        
        if (isValid) {
          recommendations.push({
            type: 'proceed',
            reason: 'Blockhash is valid'
          });
        } else {
          recommendations.push({
            type: 'abort',
            reason: 'Blockhash is invalid'
          });
          
          recommendations.push({
            type: 'retry',
            reason: 'Get a new blockhash and retry'
          });
        }
        
        return {
          blockhash,
          validity: {
            isValid,
            checkedAt: now
          },
          recommendations,
          metadata: {
            timestamp: now
          }
        };
      }
      
      async waitForValidBlockhash(
        blockhash: string,
        config: { 
          commitment?: string;
          minContextSlot?: number;
        }
      ): Promise<boolean> {
        let retries = 0;
        
        while (retries < this.maxRetries) {
          const isValid = await connection.isBlockhashValid(blockhash, config);
          
          if (isValid) {
            return true;
          }
          
          retries++;
          await new Promise(resolve => setTimeout(resolve, this.validityCheckInterval));
        }
        
        return false;
      }
    }