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

# getLatestBlockhash

> 返回最新的 blockhash

## 参数

<ParamField query="config" type="object" optional>
  <Expandable title="config fields">
    <ParamField name="commitment" type="string" optional>
      响应使用的 commitment 级别
    </ParamField>

    <ParamField name="minContextSlot" type="number" optional>
      请求可被评估的最小 slot
    </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="blockhash" type="string">
        最新的 blockhash（base-58 编码）
      </ResponseField>

      <ResponseField name="lastValidBlockHeight" type="number">
        blockhash 的最后有效区块高度
      </ResponseField>
    </ResponseField>
  </Expandable>
</ResponseField>

## 代码示例

### 基本请求

```bash theme={null}
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": "getLatestBlockhash",
  "params": [
    {"commitment": "processed"}
  ]
}'
```

### 使用 web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('http://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
console.log(blockhash, lastValidBlockHeight);
```

### 使用 Python

```python theme={null}
from solana.rpc.api import Client

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

## 注意事项

1. 此方法返回最新的 blockhash 及其有效期
2. 替代已弃用的 `getRecentBlockhash` 方法
3. blockhash 用于交易处理和去重
4. blockhash 在达到指定的 lastValidBlockHeight 之前有效
5. 可以为响应指定不同的 commitment 级别

## 最佳实践

1. 使用 blockhash 进行交易提交和签名
2. 监控 lastValidBlockHeight 以确定 blockhash 有效性
3. 如果达到或超过 lastValidBlockHeight，则刷新 blockhash
4. 适当处理网络错误并重试
5. 在有效期内缓存 blockhash 用于多个交易
