跳转到主要内容

参数

slot
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": "getBlockCommitment",
  "params": [5]
}'

使用 web3.js

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

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

使用 Python

from solana.rpc.api import Client

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

注意事项

  1. 返回特定区块的 commitment 信息
  2. commitment 数组表示质押权重分布
  3. totalStake 值代表当前 epoch 的总活跃质押量
  4. 响应是即时的,因为它从当前状态读取

最佳实践

  1. 使用此方法验证区块确认状态
  2. 比较 commitment 值以了解共识级别
  3. 适当处理网络错误并重试