Parameters

config
object

Response

result
string

Public key of the current slot leader (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": "getSlotLeader",
  "params": []
}'

Request with Commitment

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

Using web3.js

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

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

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

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

Use Cases

  1. Slot Leader Monitoring

    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

    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

    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
          }
        };
      }
    }