> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getSlotLeaders

> Returns the slot leaders for a given range

## Parameters

<ResponseField name="startSlot" type="number" required>
  Start slot number
</ResponseField>

<ResponseField name="limit" type="number" required>
  Number of slot leaders to return
</ResponseField>

## Response

<ResponseField name="result" type="array">
  Array of slot leader public keys (base-58 encoded)
</ResponseField>

## Code Examples

### Basic Request

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getSlotLeaders",
  "params": [
    1000000,
    10
  ]
}'
```

### Using web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// 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

| Code   | Message                             | Solution                                     |
| ------ | ----------------------------------- | -------------------------------------------- |
| -32601 | Method not found                    | Verify you're connected to a Solana RPC node |
| -32602 | Invalid params                      | Check startSlot and limit parameters         |
| -32007 | Slot leader information unavailable | Node may be bootstrapping or syncing         |

## Use Cases

1. **Leader Schedule Analysis**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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
         }
       };
     }
   }
   ```
