Parameters
Commitment level (processed, confirmed, finalized)
Response
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
- Returns the public key of the current slot leader
- The slot leader is responsible for producing the next block
- Different commitment levels can be specified
- The response is immediate as it reads from the current state
- The slot leader changes based on the network’s leader schedule
Best Practices
- Cache the slot leader when appropriate
- Consider using websocket subscription for real-time updates
- Handle network errors and retry when appropriate
- Use appropriate commitment level based on your needs
- 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
-
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;
}
}
-
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
}
};
}
-
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
}
};
}
}