Parameters
Number of slot leaders to return
Response
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
- Returns the slot leaders for a given range of slots
- The slot leaders are responsible for producing blocks
- The response is immediate as it reads from the current state
- The slot leaders are determined by the network’s leader schedule
- The range must be within the current epoch
Best Practices
- Use appropriate start slot and limit based on your needs
- Cache results when appropriate to reduce RPC load
- Monitor for changes in the leader schedule
- Consider using websocket subscription for real-time updates
- 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
-
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
}
};
}
-
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;
}
}
-
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
}
};
}
}