Returns the current slot leader
Show config fields
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "getSlotLeader", "params": [] }'
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "getSlotLeader", "params": [ { "commitment": "confirmed" } ] }'
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() }; }
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; } }
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 } }; }
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 } }; } }