> ## 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.

# getSlotLeader

> Returns the current slot leader

## Parameters

<ResponseField name="config" type="object" optional>
  <Expandable title="config fields">
    <ResponseField name="commitment" type="string" optional>
      Commitment level (processed, confirmed, finalized)
    </ResponseField>
  </Expandable>
</ResponseField>

## Response

<ResponseField name="result" type="string">
  Public key of the current slot leader (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": "getSlotLeader",
  "params": []
}'
```

### Request with Commitment

```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": "getSlotLeader",
  "params": [
    {
      "commitment": "confirmed"
    }
  ]
}'
```

### 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 current slot leader
const slotLeader = await connection.getSlotLeader();
console.log('Current slot leader:', slotLeader);

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

## Notes

1. Returns the public key of the current slot leader
2. The slot leader is responsible for producing the next block
3. Different commitment levels can be specified
4. The response is immediate as it reads from the current state
5. The slot leader changes based on the network's leader schedule

## Best Practices

1. Cache the slot leader 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 leader changes for network analysis

## Common Errors

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

## Use Cases

1. **Slot Leader Monitoring**
   ```typescript theme={null}
   interface SlotLeaderInfo {
     slotLeader: string;
     commitment: string;
     metadata: {
       timestamp: number;
       previousLeader: string | null;
       leaderChanged: boolean;
     };
   }

   class SlotLeaderMonitor {
     private previousLeader: string | null = null;
     
     async monitorSlotLeader(
       commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
       interval: number = 1000
     ): Promise<SlotLeaderInfo> {
       const slotLeader = await connection.getSlotLeader(commitment);
       const timestamp = Date.now();
       
       const info: SlotLeaderInfo = {
         slotLeader,
         commitment,
         metadata: {
           timestamp,
           previousLeader: this.previousLeader,
           leaderChanged: this.previousLeader !== null && this.previousLeader !== slotLeader
         }
       };
       
       this.previousLeader = slotLeader;
       return info;
     }
   }
   ```

2. **Slot Leader Analysis**
   ```typescript theme={null}
   interface SlotLeaderAnalysis {
     currentLeader: string;
     leaderChanges: Array<{
       from: string;
       to: string;
       timestamp: number;
     }>;
     leaderDistribution: Record<string, number>;
     metadata: {
       startTime: number;
       duration: number;
     };
   }

   async function analyzeSlotLeaders(
     commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
     duration: number = 60000
   ): Promise<SlotLeaderAnalysis> {
     const startTime = Date.now();
     const leaderDistribution: Record<string, number> = {};
     const leaderChanges: Array<{
       from: string;
       to: string;
       timestamp: number;
     }> = [];
     let previousLeader = await connection.getSlotLeader(commitment);
     leaderDistribution[previousLeader] = 1;
     
     while (Date.now() - startTime < duration) {
       const currentLeader = await connection.getSlotLeader(commitment);
       
       if (currentLeader !== previousLeader) {
         leaderChanges.push({
           from: previousLeader,
           to: currentLeader,
           timestamp: Date.now()
         });
         previousLeader = currentLeader;
       }
       
       leaderDistribution[currentLeader] = (leaderDistribution[currentLeader] || 0) + 1;
       await new Promise(resolve => setTimeout(resolve, 1000));
     }
     
     return {
       currentLeader: previousLeader,
       leaderChanges,
       leaderDistribution,
       metadata: {
         startTime,
         duration: Date.now() - startTime
       }
     };
   }
   ```

3. **Slot Leader Tracking**
   ```typescript theme={null}
   interface SlotLeaderTrack {
     leader: string;
     slot: number;
     metadata: {
       timestamp: number;
       commitment: string;
     };
   }

   class SlotLeaderTracker {
     async trackSlotLeader(
       commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed'
     ): Promise<SlotLeaderTrack> {
       const [leader, slot] = await Promise.all([
         connection.getSlotLeader(commitment),
         connection.getSlot()
       ]);
       
       return {
         leader,
         slot,
         metadata: {
           timestamp: Date.now(),
           commitment
         }
       };
     }
   }
   ```
