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

# getBlockProduction

> 返回当前或上一个 epoch 的近期区块生产信息

## 参数

<ParamField query="config" type="object" optional>
  包含以下可选字段的配置对象：

  <Expandable title="config fields">
    <ParamField query="commitment" type="string" optional>
      使用的 commitment 级别：

      * `processed`：最新区块（未确认）
      * `confirmed`：超级多数确认
      * `finalized`：超级多数最终确认
    </ParamField>

    <ParamField query="range" type="object" optional>
      返回区块生产信息的 slot 范围：

      * `firstSlot`: number - 返回区块生产信息的第一个 slot（包含）
      * `lastSlot`: number - 返回区块生产信息的最后一个 slot（包含）
    </ParamField>

    <ParamField query="identity" type="string" optional>
      仅返回此验证者身份的结果（base-58 编码）
    </ParamField>
  </Expandable>
</ParamField>

## 响应

<ResponseField name="result" type="object">
  <Expandable title="result fields">
    <ResponseField name="context" type="object">
      <ResponseField name="slot" type="number">
        处理请求时的 slot
      </ResponseField>
    </ResponseField>

    <ResponseField name="value" type="object">
      <ResponseField name="byIdentity" type="object">
        验证者身份字典，每个包含：

        * `leader_slots`: number - 分配为领导者的 slot 数
        * `blocks_produced`: number - 此 epoch 中生产的区块数
      </ResponseField>

      <ResponseField name="range" type="object">
        <ResponseField name="firstSlot" type="number">
          区块生产信息的第一个 slot（包含）
        </ResponseField>

        <ResponseField name="lastSlot" type="number">
          区块生产信息的最后一个 slot（包含）
        </ResponseField>
      </ResponseField>
    </ResponseField>
  </Expandable>
</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": "getBlockProduction"
}'
```

### 带范围和身份的请求

```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": "getBlockProduction",
  "params": [
    {
      "range": {
        "firstSlot": 100000000,
        "lastSlot": 100000100
      },
      "identity": "GH7ome3EiwEr17v3Fn6XY4RjS1YERxYzwXSW8kZ8kBYq"
    }
  ]
}'
```

### 使用 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');

const blockProduction = await connection.getBlockProduction();
console.log('Block production:', blockProduction);

// Get production for specific range and validator
const config = {
  range: {
    firstSlot: 100000000,
    lastSlot: 100000100
  },
  identity: 'GH7ome3EiwEr17v3Fn6XY4RjS1YERxYzwXSW8kZ8kBYq'
};
const specificProduction = await connection.getBlockProduction(config);
```

## 注意事项

1. 不带参数时，返回当前 epoch 中所有验证者的生产信息
2. `range` 参数可以跨多个 epoch
3. 区块生产统计用于跟踪验证者性能
4. 结果包括分配的领导者 slot 和实际生产的区块

## 最佳实践

1. 查询历史信息时使用 `range` 来限制数据
2. 使用 `identity` 跟踪特定验证者性能
3. 比较 `leader_slots` 和 `blocks_produced` 来评估验证者可靠性
4. 适当时缓存结果以减少 RPC 负载

## 常见错误

| 错误码    | 消息                                       | 解决方案                |
| ------ | ---------------------------------------- | ------------------- |
| -32602 | Invalid param: WrongSize                 | 验证验证者身份是否有效         |
| -32602 | Invalid param: not base58 encoded string | 确保验证者身份是 base58 编码的 |
| -32602 | Invalid param: slot range too large      | 减小 slot 范围大小        |
| -32007 | Block production not available           | 节点可能正在启动或范围太旧       |
