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.
Commitment 级别(processed、confirmed、finalized)
当前 slot 领导者的公钥(base-58 编码)
代码示例
基本请求
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 的请求
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"
}
]
}'
使用 web3.js
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()
};
}
注意事项
- 返回当前 slot 领导者的公钥
- slot 领导者负责生产下一个区块
- 可以指定不同的 commitment 级别
- 响应是即时的,因为它从当前状态读取
- slot 领导者根据网络的领导者计划进行更换
最佳实践
- 在适当时缓存 slot 领导者
- 考虑使用 WebSocket 订阅获取实时更新
- 适当处理网络错误并重试
- 根据需求使用适当的 commitment 级别
- 监控 slot 领导者变化以进行网络分析
常见错误
| 错误码 | 消息 | 解决方案 |
|---|
| -32601 | Method not found | 验证是否连接到 Solana RPC 节点 |
| -32602 | Invalid params | 检查配置参数 |
| -32007 | Slot leader information unavailable | 节点可能正在启动或同步中 |
-
Slot 领导者监控
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 领导者分析
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 领导者跟踪
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
}
};
}
}