Parameters

config
object

Response

result
number

Current slot number

Code Examples

Basic Request

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

Request with Commitment

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

Using web3.js

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

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

// Get current slot
const slot = await connection.getSlot();
console.log('Current slot:', slot);

// Get slot with commitment
async function getSlotWithCommitment(
  commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed'
) {
  const slot = await connection.getSlot(commitment);
  return {
    slot,
    commitment,
    timestamp: Date.now()
  };
}

Notes

  1. Returns the current slot of the node
  2. The slot number increases as new blocks are produced
  3. Different commitment levels can be specified
  4. The response is immediate as it reads from the current state
  5. The slot number is used for various time-based operations

Best Practices

  1. Cache the slot number when appropriate
  2. Consider using websocket subscription for real-time updates
  3. Handle network errors and retry when appropriate
  4. Use appropriate commitment level based on your needs
  5. Monitor slot progression for time-sensitive operations

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32602Invalid paramsCheck config parameters
-32007Slot information unavailableNode may be bootstrapping or syncing

Use Cases

  1. Slot Monitoring

    interface SlotInfo {
      slot: number;
      commitment: string;
      metadata: {
        timestamp: number;
        previousSlot: number | null;
        slotProgression: number;
      };
    }
    
    class SlotMonitor {
      private previousSlot: number | null = null;
      
      async monitorSlot(
        commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
        interval: number = 1000
      ): Promise<SlotInfo> {
        const slot = await connection.getSlot(commitment);
        const timestamp = Date.now();
        
        const info: SlotInfo = {
          slot,
          commitment,
          metadata: {
            timestamp,
            previousSlot: this.previousSlot,
            slotProgression: this.previousSlot !== null
              ? slot - this.previousSlot
              : 0
          }
        };
        
        this.previousSlot = slot;
        return info;
      }
    }
    
  2. Slot Analysis

    interface SlotAnalysis {
      currentSlot: number;
      slotProgression: {
        average: number;
        min: number;
        max: number;
        samples: number;
      };
      timeDistribution: {
        slotsPerSecond: number;
        slotsPerMinute: number;
        slotsPerHour: number;
      };
      metadata: {
        startTime: number;
        duration: number;
      };
    }
    
    async function analyzeSlots(
      commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
      duration: number = 60000
    ): Promise<SlotAnalysis> {
      const startTime = Date.now();
      const startSlot = await connection.getSlot(commitment);
      const progressions: number[] = [];
      let previousSlot = startSlot;
      
      while (Date.now() - startTime < duration) {
        const currentSlot = await connection.getSlot(commitment);
        progressions.push(currentSlot - previousSlot);
        previousSlot = currentSlot;
        await new Promise(resolve => setTimeout(resolve, 1000));
      }
      
      const totalProgression = progressions.reduce((sum, p) => sum + p, 0);
      const durationSeconds = (Date.now() - startTime) / 1000;
      
      return {
        currentSlot: previousSlot,
        slotProgression: {
          average: totalProgression / progressions.length,
          min: Math.min(...progressions),
          max: Math.max(...progressions),
          samples: progressions.length
        },
        timeDistribution: {
          slotsPerSecond: totalProgression / durationSeconds,
          slotsPerMinute: (totalProgression / durationSeconds) * 60,
          slotsPerHour: (totalProgression / durationSeconds) * 3600
        },
        metadata: {
          startTime,
          duration: Date.now() - startTime
        }
      };
    }
    
  3. Slot Synchronization

    interface SlotSync {
      currentSlot: number;
      targetSlot: number;
      difference: number;
      estimatedTime: number;
      metadata: {
        timestamp: number;
        commitment: string;
      };
    }
    
    class SlotSynchronizer {
      private readonly targetSlotsPerSecond = 2; // Solana's target slot rate
      
      async checkSynchronization(
        commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed'
      ): Promise<SlotSync> {
        const currentSlot = await connection.getSlot(commitment);
        const targetSlot = Math.floor(
          (Date.now() / 1000) * this.targetSlotsPerSecond
        );
        
        return {
          currentSlot,
          targetSlot,
          difference: currentSlot - targetSlot,
          estimatedTime: Math.abs(currentSlot - targetSlot) / this.targetSlotsPerSecond,
          metadata: {
            timestamp: Date.now(),
            commitment
          }
        };
      }
    }