Parameters

This method does not take any parameters.

Response

result
number

The slot of the lowest confirmed block available

Code Examples

Basic Request

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

Using web3.js

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

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

// Get first available block
const firstBlock = await connection.getFirstAvailableBlock();
console.log('First available block:', firstBlock);

// Get block range
async function getAvailableBlockRange() {
  const firstBlock = await connection.getFirstAvailableBlock();
  const currentSlot = await connection.getSlot();
  
  return {
    firstBlock,
    currentSlot,
    totalBlocks: currentSlot - firstBlock + 1
  };
}

Notes

  1. Returns the slot of the lowest confirmed block available
  2. This is useful for determining the node’s available history
  3. The value may change as the node prunes old blocks
  4. Different nodes may return different values
  5. The response is immediate as it reads from the current state

Best Practices

  1. Use this method to determine available block range
  2. Consider node pruning when querying historical blocks
  3. Cache results when appropriate to reduce RPC load
  4. Handle cases where requested blocks are not available
  5. Use in conjunction with other block methods

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32007Block information unavailableNode may be bootstrapping or syncing

Use Cases

  1. Block Range Verification

    async function verifyBlockRange(startSlot: number, endSlot: number) {
      const firstBlock = await connection.getFirstAvailableBlock();
      const currentSlot = await connection.getSlot();
      
      if (startSlot < firstBlock) {
        throw new Error(`Start slot ${startSlot} is before first available block ${firstBlock}`);
      }
      
      if (endSlot > currentSlot) {
        throw new Error(`End slot ${endSlot} is after current slot ${currentSlot}`);
      }
      
      return {
        startSlot,
        endSlot,
        available: true
      };
    }
    
  2. Historical Data Availability

    interface BlockAvailability {
      firstAvailable: number;
      currentSlot: number;
      availableRange: number;
      requestedSlot: number;
      isAvailable: boolean;
    }
    
    async function checkBlockAvailability(slot: number): Promise<BlockAvailability> {
      const firstBlock = await connection.getFirstAvailableBlock();
      const currentSlot = await connection.getSlot();
      
      return {
        firstAvailable: firstBlock,
        currentSlot,
        availableRange: currentSlot - firstBlock + 1,
        requestedSlot: slot,
        isAvailable: slot >= firstBlock && slot <= currentSlot
      };
    }
    
  3. Block History Analysis

    async function analyzeBlockHistory() {
      const firstBlock = await connection.getFirstAvailableBlock();
      const currentSlot = await connection.getSlot();
      const blocks = await connection.getBlocks(firstBlock, currentSlot);
      
      const metrics = {
        firstBlock,
        currentSlot,
        totalSlots: currentSlot - firstBlock + 1,
        availableBlocks: blocks.length,
        missingBlocks: (currentSlot - firstBlock + 1) - blocks.length,
        availabilityPercentage: (blocks.length / (currentSlot - firstBlock + 1)) * 100
      };
      
      return metrics;
    }