跳转到主要内容

参数

此方法不接受任何参数。

响应

result
array
包含节点信息的对象数组:

代码示例

基本请求

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": "getClusterNodes"
}'

使用 web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

const nodes = await connection.getClusterNodes();
console.log('Cluster nodes:', nodes);

// Example: Find all nodes running a specific version
const version = '1.16.0';
const nodesWithVersion = nodes.filter(node => node.version === version);
console.log(`Nodes running version ${version}:`, nodesWithVersion);

// Example: Get all RPC endpoints
const rpcEndpoints = nodes
  .filter(node => node.rpc)
  .map(node => node.rpc);
console.log('Available RPC endpoints:', rpcEndpoints);

注意事项

  1. 某些字段如果信息不可用可能为 null
  2. 节点信息通过 gossip 网络获取
  3. 列表包含所有已知节点,无论它们当前是否活跃
  4. 网络地址采用标准 socket 格式(IP:端口)

最佳实践

  1. 缓存结果以减少 RPC 负载(每隔几分钟刷新一次)
  2. 使用版本信息检测网络升级
  3. 处理网络地址时过滤 null 值
  4. 选择 RPC 端点时考虑节点版本
  5. 使用 TPU 地址优化交易转发

常见错误

错误码消息解决方案
-32601Method not found验证是否连接到 Solana RPC 节点
-32007Node information unavailable节点可能正在启动或 gossip 服务可能已停止
-32008Node list too large稍后网络条件改善时重试

用例

  1. 负载均衡
    • 发现可用的 RPC 端点
    • 分配客户端连接
  2. 网络健康监控
    • 跟踪节点版本
    • 监控网络分布
    • 识别网络分区
  3. 交易优化
    • 查找最近的 TPU 地址
    • 实现领导者感知的交易转发
  4. 版本管理
    • 跟踪网络升级
    • 确保客户端兼容性
    • 规划维护窗口