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.
包含以下可选字段的配置对象:
使用的 commitment 级别:
processed:最新区块(未确认)
confirmed:超级多数确认
finalized:超级多数最终确认
代码示例
基本请求
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": "getBalance",
"params": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
]
}'
带 Commitment 的请求
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": "getBalance",
"params": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri",
{
"commitment": "finalized"
}
]
}'
使用 web3.js
import { Connection, PublicKey } from '@solana/web3.js';
const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');
const publicKey = new PublicKey('83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri');
const balance = await connection.getBalance(
publicKey,
'confirmed'
);
console.log(`Balance: ${balance / 1e9} SOL`);
注意事项
- 余额以 lamports 返回(1 SOL = 1,000,000,000 lamports)
- 对于新账户,余额为 0
- 余额包括所有 SOL 代币,包括委托用于质押的代币
- 响应是即时的,因为它从当前状态读取
最佳实践
- 根据需求使用适当的 commitment 级别:
processed 用于 UI 更新
confirmed 用于大多数操作
finalized 用于关键操作
- 向用户显示时,将 lamports 除以 1e9 转换为 SOL
- 如果需要更多账户详情,请考虑使用
getAccountInfo
常见错误
| 错误码 | 消息 | 解决方案 |
|---|
| -32602 | Invalid param: WrongSize | 验证公钥是否有效 |
| -32602 | Invalid param: not base58 encoded string | 确保公钥是 base58 编码的 |
| -32007 | Account not found | 账户不存在(余额将为 0) |