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

# getTokenAccounts

> 在 OrbitFlare 上使用 DAS getTokenAccounts，按所有者或按 mint 分页列出 SPL Token 和 Token-2022 账户。

## 概述

`getTokenAccounts` 按所有者、按 mint 或同时按两者筛选并列出代币账户。按 mint 筛选可以分页浏览某个代币的所有持有者；按所有者筛选可以列出某个钱包的代币账户。与 [getProgramAccounts](/cn/rpc/methods/getProgramAccounts) 不同，它支持分页，因此适用于拥有数百万持有者的 mint。

除非设置了 `showZeroBalance`，否则余额为零的账户会被排除。

## 参数

至少传入 `owner` 和 `mint` 中的一个。

<ResponseField name="owner" type="string">
  所有者钱包（base-58）。也可以作为 `ownerAddress` 传入。
</ResponseField>

<ResponseField name="mint" type="string">
  代币 mint（base-58）。也可以作为 `mintAddress` 传入。
</ResponseField>

<ResponseField name="page" type="number">
  页码，从 1 开始。请参阅[分页](/cn/das-api/pagination)。
</ResponseField>

<ResponseField name="limit" type="number">
  每页结果数。最大值和默认值均为 1,000。
</ResponseField>

<ResponseField name="cursor" type="string">
  来自上一次响应的游标。
</ResponseField>

<ResponseField name="before" type="string">
  返回此账户之前的账户。
</ResponseField>

<ResponseField name="after" type="string">
  返回此账户之后的账户。
</ResponseField>

<ResponseField name="options" type="object">
  [显示选项](/cn/das-api/display-options)：`showZeroBalance`。也可以作为 `displayOptions` 传入。
</ResponseField>

## 响应

<ResponseField name="result" type="object">
  <Expandable title="result 字段">
    <ResponseField name="total" type="number">
      本页中的账户数量。
    </ResponseField>

    <ResponseField name="limit" type="number">
      使用的每页大小。
    </ResponseField>

    <ResponseField name="page" type="number">
      按页码分页时的页码。
    </ResponseField>

    <ResponseField name="cursor" type="string">
      按游标分页时，用于获取下一页的游标。
    </ResponseField>

    <ResponseField name="token_accounts" type="array">
      <Expandable title="代币账户字段">
        <ResponseField name="address" type="string">
          代币账户地址。
        </ResponseField>

        <ResponseField name="mint" type="string">
          mint 地址。
        </ResponseField>

        <ResponseField name="owner" type="string">
          所有者钱包。
        </ResponseField>

        <ResponseField name="amount" type="number">
          以基础单位计的余额。
        </ResponseField>

        <ResponseField name="delegate" type="string | null">
          委托人（如已设置）。
        </ResponseField>

        <ResponseField name="delegated_amount" type="number">
          委托人可以转移的数量。
        </ResponseField>

        <ResponseField name="close_authority" type="string | null">
          关闭权限（如已设置）。
        </ResponseField>

        <ResponseField name="frozen" type="boolean">
          该账户是否被冻结。
        </ResponseField>

        <ResponseField name="token_extensions" type="object">
          Token-2022 账户扩展（如存在）。
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## 代码示例

### 某个 mint 的持有者

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
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": "getTokenAccounts",
  "params": {
    "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "page": 1,
    "limit": 2
  }
}'
```

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
{
  "jsonrpc": "2.0",
  "result": {
    "total": 2,
    "limit": 2,
    "page": 1,
    "token_accounts": [
      {
        "address": "1113odRAP5wXa8n7NFVBG53XrqWeDrViZu5rSiSsVA3",
        "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "owner": "HJNr4feTNiDn59RCL1pYoARXMFoBEQSmAY7R7Cm21z9T",
        "amount": 170812,
        "delegate": null,
        "delegated_amount": 0,
        "close_authority": null,
        "frozen": false
      },
      {
        "address": "11NCSQ2Bm6UZdtDqBeHFcos5eFXT1kJ3jG29qKJCWU",
        "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "owner": "FRPPBdG4sYCH7EnTMeKFSVLsfzfEUo4PQ1wWCUkzzmuv",
        "amount": 1804811,
        "delegate": null,
        "delegated_amount": 0,
        "close_authority": null,
        "frozen": false
      }
    ]
  },
  "id": 1
}
```

### 统计某个代币的全部持有者

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const RPC_URL = 'https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY';

async function countHolders(mint: string) {
  const owners = new Set<string>();
  let cursor: string | undefined;

  while (true) {
    const response = await fetch(RPC_URL, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getTokenAccounts',
        params: { mint, limit: 1000, cursor },
      }),
    });
    const { result, error } = await response.json();
    if (error) throw new Error(error.message);

    for (const account of result.token_accounts) owners.add(account.owner);
    if (result.token_accounts.length < 1000) break;
    cursor = result.cursor;
  }

  return owners.size;
}
```

## 常见错误

| 错误码 | 消息 | 解决方案 |
| - | - | - |
| -32602 | Validation Error: Pass 'owner', 'mint' or both (also accepted as 'ownerAddress' and 'mintAddress') | 发送 `owner`、`mint` 或两者 |
| -32602 | Validation Error: Invalid pubkey ... | 传入有效的 base-58 地址 |
| -32602 | Pagination Error. Limit should not be greater than 1000. | 使用不超过 1,000 的 `limit` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.