跳转到主要内容

参数

commitment
string
commitment 描述了区块在该时间点的最终确认程度。
minContextSlot
number
请求可被评估的最小 slot。

响应

result
object

代码示例

基本请求

curl http://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getEpochInfo"
}'

使用 web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('http://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
const epochInfo = await connection.getEpochInfo();
console.log(epochInfo);

使用 Python

from solana.rpc.api import Client

client = Client("http://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY")
response = client.get_epoch_info()
print(response)

注意事项

  1. 返回当前 epoch 的详细信息
  2. 包括绝对 slot、区块高度、epoch 编号和 epoch 中的 slot 数
  3. 交易计数如果不可用可能为 null
  4. 可以指定不同的 commitment 级别
  5. 响应是即时的,因为它从当前状态读取

最佳实践

  1. 使用此方法跟踪 epoch 过渡
  2. 监控交易计数以了解网络活动
  3. 检查 slot 索引以确定当前 epoch 的进度
  4. 适当处理网络错误并重试
  5. 根据需求使用适当的 commitment 级别