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

# getBlockHeight

> 返回节点当前的区块高度

## 参数

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

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

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

    <ParamField query="minContextSlot" type="number" optional>
      请求可被评估的最小 slot
    </ParamField>
  </Expandable>
</ParamField>

## 响应

<ResponseField name="result" type="number">
  当前区块高度
</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": "getBlockHeight"
}'
```

### 带 Commitment 的请求

```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": "getBlockHeight",
  "params": [
    {
      "commitment": "finalized"
    }
  ]
}'
```

### 使用 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 blockHeight = await connection.getBlockHeight('finalized');
console.log(`Current block height: ${blockHeight}`);
```

## 注意事项

1. 区块高度随每个新区块单调递增
2. 由于跳过的 slot，区块高度可能与 slot 编号不同
3. 不同的节点可能根据其网络视图返回略有不同的高度
4. 响应是即时的，因为它从当前状态读取

## 最佳实践

1. 根据需求使用适当的 commitment 级别：
   * `processed` 获取最新的可能高度
   * `confirmed` 获取高概率最终性
   * `finalized` 获取保证的最终性
2. 如果需要 slot 编号而不是区块高度，请考虑使用 `getSlot`
3. 对于历史查询，使用 `getBlock` 与特定 slot

## 常见错误

| 错误码    | 消息                         | 解决方案                  |
| ------ | -------------------------- | --------------------- |
| -32601 | Method not found           | 验证是否连接到 Solana RPC 节点 |
| -32007 | Block height not available | 节点可能正在启动或同步中          |
