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

# getBlockTime

> 返回区块的估计生产时间

## 参数

<ParamField query="slot" type="number" required>
  要获取区块时间的 slot
</ParamField>

## 响应

<ResponseField name="result" type="number | null">
  区块生产时的 Unix 时间戳，如果区块不可用则为 null
</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": "getBlockTime",
  "params": [
    100000000
  ]
}'
```

### 使用 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 block time
const blockTime = await connection.getBlockTime(100000000);
if (blockTime !== null) {
  console.log('Block time:', new Date(blockTime * 1000));
} else {
  console.log('Block not available');
}

// Get multiple block times
async function getBlockTimes(slots: number[]) {
  const times = await Promise.all(
    slots.map(slot => connection.getBlockTime(slot))
  );
  
  return times.map((time, index) => ({
    slot: slots[index],
    time: time ? new Date(time * 1000) : null
  }));
}
```

## 注意事项

1. 返回区块生产时的 Unix 时间戳
2. 如果区块不可用则返回 null
3. 时间戳以 Unix 纪元以来的秒数表示
4. 区块时间是估计值，不同节点之间可能有所不同
5. 较旧的区块可能没有可用的时间戳

## 最佳实践

1. 适当处理 null 响应
2. 将 Unix 时间戳转换为 Date 对象以便显示
3. 显示时间时考虑时区差异
4. 适当时缓存结果以减少 RPC 负载
5. 将此方法与其他区块方法结合使用

## 常见错误

| 错误码    | 消息                       | 解决方案                  |
| ------ | ------------------------ | --------------------- |
| -32601 | Method not found         | 验证是否连接到 Solana RPC 节点 |
| -32007 | Block time not available | 区块可能太旧或尚未生产           |
