commitment 描述了区块在该时间点的最终确认程度。
代码示例
基本请求
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)
注意事项
- 返回当前 epoch 的详细信息
- 包括绝对 slot、区块高度、epoch 编号和 epoch 中的 slot 数
- 交易计数如果不可用可能为 null
- 可以指定不同的 commitment 级别
- 响应是即时的,因为它从当前状态读取
最佳实践
- 使用此方法跟踪 epoch 过渡
- 监控交易计数以了解网络活动
- 检查 slot 索引以确定当前 epoch 的进度
- 适当处理网络错误并重试
- 根据需求使用适当的 commitment 级别