> ## 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.

# getSlot

> 返回节点的当前 slot

## 参数

<ResponseField name="config" type="object" optional>
  <Expandable title="config fields">
    <ResponseField name="commitment" type="string" optional>
      Commitment 级别（processed、confirmed、finalized）
    </ResponseField>
  </Expandable>
</ResponseField>

## 响应

<ResponseField name="result" type="number">
  当前 slot 编号
</ResponseField>

## 代码示例

### 基本请求

```bash theme={null}
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": "getSlot",
  "params": []
}'
```

### 带 Commitment 的请求

```bash theme={null}
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": "getSlot",
  "params": [
    {
      "commitment": "confirmed"
    }
  ]
}'
```

### 使用 web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get current slot
const slot = await connection.getSlot();
console.log('Current slot:', slot);

// Get slot with commitment
async function getSlotWithCommitment(
  commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed'
) {
  const slot = await connection.getSlot(commitment);
  return {
    slot,
    commitment,
    timestamp: Date.now()
  };
}
```

## 注意事项

1. 返回节点的当前 slot
2. 随着新区块的生产，slot 编号会增加
3. 可以指定不同的 commitment 级别
4. 响应是即时的，因为它从当前状态读取
5. slot 编号用于各种基于时间的操作

## 最佳实践

1. 在适当时缓存 slot 编号
2. 考虑使用 WebSocket 订阅获取实时更新
3. 适当处理网络错误并重试
4. 根据需求使用适当的 commitment 级别
5. 监控 slot 进度以用于时间敏感的操作

## 常见错误

| 错误码    | 消息                           | 解决方案                  |
| ------ | ---------------------------- | --------------------- |
| -32601 | Method not found             | 验证是否连接到 Solana RPC 节点 |
| -32602 | Invalid params               | 检查配置参数                |
| -32007 | Slot information unavailable | 节点可能正在启动或同步中          |

## 用例

1. **Slot 监控**
   ```typescript theme={null}
   interface SlotInfo {
     slot: number;
     commitment: string;
     metadata: {
       timestamp: number;
       previousSlot: number | null;
       slotProgression: number;
     };
   }

   class SlotMonitor {
     private previousSlot: number | null = null;
     
     async monitorSlot(
       commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
       interval: number = 1000
     ): Promise<SlotInfo> {
       const slot = await connection.getSlot(commitment);
       const timestamp = Date.now();
       
       const info: SlotInfo = {
         slot,
         commitment,
         metadata: {
           timestamp,
           previousSlot: this.previousSlot,
           slotProgression: this.previousSlot !== null
             ? slot - this.previousSlot
             : 0
         }
       };
       
       this.previousSlot = slot;
       return info;
     }
   }
   ```

2. **Slot 分析**
   ```typescript theme={null}
   interface SlotAnalysis {
     currentSlot: number;
     slotProgression: {
       average: number;
       min: number;
       max: number;
       samples: number;
     };
     timeDistribution: {
       slotsPerSecond: number;
       slotsPerMinute: number;
       slotsPerHour: number;
     };
     metadata: {
       startTime: number;
       duration: number;
     };
   }

   async function analyzeSlots(
     commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed',
     duration: number = 60000
   ): Promise<SlotAnalysis> {
     const startTime = Date.now();
     const startSlot = await connection.getSlot(commitment);
     const progressions: number[] = [];
     let previousSlot = startSlot;
     
     while (Date.now() - startTime < duration) {
       const currentSlot = await connection.getSlot(commitment);
       progressions.push(currentSlot - previousSlot);
       previousSlot = currentSlot;
       await new Promise(resolve => setTimeout(resolve, 1000));
     }
     
     const totalProgression = progressions.reduce((sum, p) => sum + p, 0);
     const durationSeconds = (Date.now() - startTime) / 1000;
     
     return {
       currentSlot: previousSlot,
       slotProgression: {
         average: totalProgression / progressions.length,
         min: Math.min(...progressions),
         max: Math.max(...progressions),
         samples: progressions.length
       },
       timeDistribution: {
         slotsPerSecond: totalProgression / durationSeconds,
         slotsPerMinute: (totalProgression / durationSeconds) * 60,
         slotsPerHour: (totalProgression / durationSeconds) * 3600
       },
       metadata: {
         startTime,
         duration: Date.now() - startTime
       }
     };
   }
   ```

3. **Slot 同步**
   ```typescript theme={null}
   interface SlotSync {
     currentSlot: number;
     targetSlot: number;
     difference: number;
     estimatedTime: number;
     metadata: {
       timestamp: number;
       commitment: string;
     };
   }

   class SlotSynchronizer {
     private readonly targetSlotsPerSecond = 2; // Solana's target slot rate
     
     async checkSynchronization(
       commitment: 'processed' | 'confirmed' | 'finalized' = 'confirmed'
     ): Promise<SlotSync> {
       const currentSlot = await connection.getSlot(commitment);
       const targetSlot = Math.floor(
         (Date.now() / 1000) * this.targetSlotsPerSecond
       );
       
       return {
         currentSlot,
         targetSlot,
         difference: currentSlot - targetSlot,
         estimatedTime: Math.abs(currentSlot - targetSlot) / this.targetSlotsPerSecond,
         metadata: {
           timestamp: Date.now(),
           commitment
         }
       };
     }
   }
   ```
