跳转到主要内容

参数

slot
number
必填
要检索的区块的 slot 编号
config
object
包含以下可选字段的配置对象:

响应

result
object | null
如果未找到区块,返回 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": "getBlock",
  "params": [
    430,
    {
      "encoding": "json",
      "transactionDetails": "full",
      "rewards": true
    }
  ]
}'

带解析交易数据的请求

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": "getBlock",
  "params": [
    430,
    {
      "encoding": "jsonParsed",
      "transactionDetails": "full",
      "rewards": true,
      "maxSupportedTransactionVersion": 0
    }
  ]
}'

使用 web3.js

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

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

const block = await connection.getBlock(
  slot,
  {
    maxSupportedTransactionVersion: 0
  }
);

注意事项

  1. 区块生产时间是基于创世区块时间和已经过的 slot 的估计值。
  2. 并非所有区块都包含奖励。
  3. jsonParsed 编码会尝试根据已知的程序布局解析交易指令数据。
  4. 某些区块可能被跳过(未分配领导者或区块生产失败)。
  5. 区块数据可能会根据账本配置从节点中被修剪。

最佳实践

  1. 如果只需要交易签名,请使用 transactionDetails: "signatures"
  2. 如果不需要奖励数据,请设置 rewards: false
  3. 如果需要最新区块,请考虑先使用 getBlockHeight
  4. 对于实时更新,请考虑使用 WebSocket 订阅。

常见错误

错误码消息解决方案
-32004Block not available for slot区块已被修剪或跳过
-32602Invalid param: WrongSize验证 slot 编号是否有效
-32602Invalid param: Too large请求一个更近期的区块
-32009Transaction version unsupported指定 maxSupportedTransactionVersion