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.
最新的 blockhash(base-58 编码)
代码示例
基本请求
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
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
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)
注意事项
- 此方法返回最新的 blockhash 及其有效期
- 替代已弃用的
getRecentBlockhash 方法
- blockhash 用于交易处理和去重
- blockhash 在达到指定的 lastValidBlockHeight 之前有效
- 可以为响应指定不同的 commitment 级别
最佳实践
- 使用 blockhash 进行交易提交和签名
- 监控 lastValidBlockHeight 以确定 blockhash 有效性
- 如果达到或超过 lastValidBlockHeight,则刷新 blockhash
- 适当处理网络错误并重试
- 在有效期内缓存 blockhash 用于多个交易