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

# getLargestAccounts

> 返回按 lamport 余额排序的前 20 个最大账户

## 参数

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

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

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

    <ParamField query="filter" type="string" optional>
      按账户类型过滤结果：

      * `circulating`：过滤为流通账户
      * `nonCirculating`：过滤为非流通账户
    </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="array">
      包含账户信息的对象数组：

      <ResponseField name="address" type="string">
        账户地址（base-58 编码）
      </ResponseField>

      <ResponseField name="lamports" type="number">
        账户中的 lamports 数量
      </ResponseField>
    </ResponseField>
  </Expandable>
</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": "getLargestAccounts"
}'
```

### 带过滤器的请求

```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": "getLargestAccounts",
  "params": [
    {
      "filter": "circulating"
    }
  ]
}'
```

### 使用 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');

// Get all largest accounts
const largestAccounts = await connection.getLargestAccounts();
console.log('Largest accounts:', largestAccounts);

// Get circulating accounts only
const circulatingAccounts = await connection.getLargestAccounts({
  filter: 'circulating'
});
console.log('Largest circulating accounts:', circulatingAccounts);
```

## 注意事项

1. 返回按 lamport 余额排序的前 20 个账户
2. 结果按余额降序排序
3. 流通账户是不属于系统程序的账户
4. 非流通账户通常属于系统程序
5. 响应是即时的，因为它从当前状态读取

## 最佳实践

1. 根据需求使用适当的 commitment 级别：
   * `processed` 用于 UI 更新
   * `confirmed` 用于大多数操作
   * `finalized` 用于关键操作
2. 使用 `filter` 参数关注相关账户
3. 在向用户显示时除以 1e9 将 lamports 转换为 SOL
4. 考虑缓存结果以用于 UI 更新以减少 RPC 负载

## 常见错误

| 错误码    | 消息                              | 解决方案                                |
| ------ | ------------------------------- | ----------------------------------- |
| -32602 | Invalid param: Invalid filter   | 使用 'circulating' 或 'nonCirculating' |
| -32601 | Method not found                | 验证是否连接到 Solana RPC 节点               |
| -32007 | Account information unavailable | 节点可能正在启动或同步中                        |

## 用例

1. **网络分析**
   ```typescript theme={null}
   async function analyzeNetworkDistribution() {
     const accounts = await connection.getLargestAccounts();
     const total = accounts.reduce((sum, acc) => sum + acc.lamports, 0);
     const top20Percentage = accounts.reduce((sum, acc) => sum + acc.lamports, 0) / total;
     console.log(`Top 20 accounts hold ${top20Percentage * 100}% of total SOL`);
   }
   ```

2. **代币分布监控**
   ```typescript theme={null}
   async function monitorTokenDistribution() {
     const circulating = await connection.getLargestAccounts({ filter: 'circulating' });
     const nonCirculating = await connection.getLargestAccounts({ filter: 'nonCirculating' });
     
     const circulatingTotal = circulating.reduce((sum, acc) => sum + acc.lamports, 0);
     const nonCirculatingTotal = nonCirculating.reduce((sum, acc) => sum + acc.lamports, 0);
     
     console.log('Circulating supply:', circulatingTotal / 1e9, 'SOL');
     console.log('Non-circulating supply:', nonCirculatingTotal / 1e9, 'SOL');
   }
   ```

3. **巨鲸监控**
   ```typescript theme={null}
   interface WhaleAlert {
     address: string;
     balance: number;
     change: number;
   }

   async function trackWhaleMovements(previousAccounts: any[]) {
     const currentAccounts = await connection.getLargestAccounts();
     const alerts: WhaleAlert[] = [];
     
     for (const current of currentAccounts) {
       const previous = previousAccounts.find(p => p.address === current.address);
       if (previous) {
         const change = current.lamports - previous.lamports;
         if (Math.abs(change) > 1e9) { // Alert on changes > 1 SOL
           alerts.push({
             address: current.address,
             balance: current.lamports / 1e9,
             change: change / 1e9
           });
         }
       }
     }
     
     return alerts;
   }
   ```
