Parameters

startSlot
number
required

Start slot number

limit
number
required

Number of slot leaders to return

Response

result
array

Array of slot leader public keys (base-58 encoded)

Code Examples

Basic Request

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

Using web3.js

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

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

// Get slot leaders
const slotLeaders = await connection.getSlotLeaders(1000000, 10);
console.log('Slot leaders:', slotLeaders);

// Get slot leaders with analysis
async function getSlotLeadersWithAnalysis(
  startSlot: number,
  limit: number
) {
  const slotLeaders = await connection.getSlotLeaders(startSlot, limit);
  
  return {
    slotLeaders,
    analysis: {
      uniqueLeaders: new Set(slotLeaders).size,
      leaderDistribution: slotLeaders.reduce((acc, leader) => {
        acc[leader] = (acc[leader] || 0) + 1;
        return acc;
      }, {} as Record<string, number>),
      metadata: {
        startSlot,
        endSlot: startSlot + limit - 1,
        timestamp: Date.now()
      }
    }
  };
}

Notes

  1. Returns the slot leaders for a given range of slots
  2. The slot leaders are responsible for producing blocks
  3. The response is immediate as it reads from the current state
  4. The slot leaders are determined by the network’s leader schedule
  5. The range must be within the current epoch

Best Practices

  1. Use appropriate start slot and limit based on your needs
  2. Cache results when appropriate to reduce RPC load
  3. Monitor for changes in the leader schedule
  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 startSlot and limit parameters
-32007Slot leader information unavailableNode may be bootstrapping or syncing

Use Cases

  1. Leader Schedule Analysis

    interface LeaderScheduleAnalysis {
      schedule: Array<{
        slot: number;
        leader: string;
      }>;
      distribution: Record<string, number>;
      metadata: {
        startSlot: number;
        endSlot: number;
        uniqueLeaders: number;
      };
    }
    
    async function analyzeLeaderSchedule(
      startSlot: number,
      limit: number
    ): Promise<LeaderScheduleAnalysis> {
      const slotLeaders = await connection.getSlotLeaders(startSlot, limit);
      
      const schedule = slotLeaders.map((leader, index) => ({
        slot: startSlot + index,
        leader
      }));
      
      const distribution = slotLeaders.reduce((acc, leader) => {
        acc[leader] = (acc[leader] || 0) + 1;
        return acc;
      }, {} as Record<string, number>);
      
      return {
        schedule,
        distribution,
        metadata: {
          startSlot,
          endSlot: startSlot + limit - 1,
          uniqueLeaders: Object.keys(distribution).length
        }
      };
    }
    
  2. Leader Schedule Monitoring

    interface LeaderScheduleChange {
      slot: number;
      previousLeader: string;
      currentLeader: string;
      metadata: {
        timestamp: number;
      };
    }
    
    class LeaderScheduleMonitor {
      private previousSchedule: Map<number, string> = new Map();
      
      async monitorLeaderSchedule(
        startSlot: number,
        limit: number,
        interval: number = 60000
      ): Promise<LeaderScheduleChange[]> {
        const slotLeaders = await connection.getSlotLeaders(startSlot, limit);
        const changes: LeaderScheduleChange[] = [];
        
        slotLeaders.forEach((leader, index) => {
          const slot = startSlot + index;
          const previousLeader = this.previousSchedule.get(slot);
          
          if (previousLeader && previousLeader !== leader) {
            changes.push({
              slot,
              previousLeader,
              currentLeader: leader,
              metadata: {
                timestamp: Date.now()
              }
            });
          }
          
          this.previousSchedule.set(slot, leader);
        });
        
        return changes;
      }
    }
    
  3. Leader Schedule Planning

    interface LeaderSchedulePlan {
      currentSlot: number;
      upcomingLeaders: Array<{
        slot: number;
        leader: string;
        estimatedTime: number;
      }>;
      metadata: {
        timestamp: number;
        slotsPerSecond: number;
      };
    }
    
    class LeaderSchedulePlanner {
      private readonly slotsPerSecond = 2; // Solana's target slot rate
      
      async planLeaderSchedule(
        startSlot: number,
        limit: number
      ): Promise<LeaderSchedulePlan> {
        const [slotLeaders, currentSlot] = await Promise.all([
          connection.getSlotLeaders(startSlot, limit),
          connection.getSlot()
        ]);
        
        const upcomingLeaders = slotLeaders.map((leader, index) => {
          const slot = startSlot + index;
          const slotsAhead = slot - currentSlot;
          const estimatedTime = slotsAhead / this.slotsPerSecond;
          
          return {
            slot,
            leader,
            estimatedTime
          };
        });
        
        return {
          currentSlot,
          upcomingLeaders,
          metadata: {
            timestamp: Date.now(),
            slotsPerSecond: this.slotsPerSecond
          }
        };
      }
    }