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

> Returns the 20 largest accounts, by lamport balance

## Parameters

<ParamField query="config" type="object" optional>
  Configuration object containing the following optional fields:

  <Expandable title="config fields">
    <ParamField query="commitment" type="string" optional>
      The level of commitment to use:

      * `processed`: Latest block (unconfirmed)
      * `confirmed`: Confirmed by supermajority
      * `finalized`: Finalized by supermajority
    </ParamField>

    <ParamField query="filter" type="string" optional>
      Filter results by account type:

      * `circulating`: Filter to circulating accounts
      * `nonCirculating`: Filter to non-circulating accounts
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="result" type="object">
  <Expandable title="result fields">
    <ResponseField name="context" type="object">
      <ResponseField name="slot" type="number">
        The slot the request was processed at
      </ResponseField>
    </ResponseField>

    <ResponseField name="value" type="array">
      Array of objects containing account information:

      <ResponseField name="address" type="string">
        Address of the account (base-58 encoded)
      </ResponseField>

      <ResponseField name="lamports" type="number">
        Number of lamports in the account
      </ResponseField>
    </ResponseField>
  </Expandable>
</ResponseField>

## Code Examples

### Basic Request

```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"
}'
```

### Request with Filter

```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"
    }
  ]
}'
```

### Using 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);
```

## Notes

1. Returns the top 20 accounts by lamport balance
2. Results are sorted in descending order by balance
3. Circulating accounts are those not owned by the system program
4. Non-circulating accounts are typically owned by the system program
5. The response is immediate as it reads from the current state

## Best Practices

1. Use appropriate commitment level based on your needs:
   * `processed` for UI updates
   * `confirmed` for most operations
   * `finalized` for critical operations
2. Use the `filter` parameter to focus on relevant accounts
3. Convert lamports to SOL by dividing by 1e9 when displaying to users
4. Consider caching results for UI updates to reduce RPC load

## Common Errors

| Code   | Message                         | Solution                                     |
| ------ | ------------------------------- | -------------------------------------------- |
| -32602 | Invalid param: Invalid filter   | Use either 'circulating' or 'nonCirculating' |
| -32601 | Method not found                | Verify you're connected to a Solana RPC node |
| -32007 | Account information unavailable | Node may be bootstrapping or syncing         |

## Use Cases

1. **Network Analysis**
   ```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. **Token Distribution Monitoring**
   ```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. **Whale Watching**
   ```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;
   }
   ```
