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

# 分页

> 在 OrbitFlare 上使用页码、游标或 before/after 范围浏览 DAS API 结果，并选择排序方式和数量限制。

## 概述

所有 DAS 列表方法（`getAssetsByOwner`、`getAssetsByGroup`、`getAssetsByCreator`、`getAssetsByAuthority`、`searchAssets`、`getTokenAccounts`、`getNftEditions` 和 `getSignaturesForAsset`）都按页返回结果。你可以通过三种方式分页：

| 方式 | 参数 | 适用场景 |
| - | - | - |
| 页码 | `page` | 小型结果集和带编号页面的 UI |
| 游标 | `cursor` | 从头到尾遍历大型结果集 |
| 范围 | `before`、`after` | 获取两个资产 ID 之间的一段结果 |

每个请求只能使用一种方式。将 `page` 与 `cursor`、`before` 或 `after` 混用，或将 `cursor` 与 `before` 或 `after` 混用，都会返回 `-32602`。

## 限制

* `limit` 设置每页大小。最大值和默认值均为 1,000。
* `page` 从 1 开始。`page: 0` 会被拒绝。
* 批量方法（`getAssetBatch`、`getAssetProofBatch`）最多接受 1,000 个 ID。

## 页码

传入 `page` 和 `limit`。响应会回传 `page`：

```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": "getAssetsByGroup",
  "params": {
    "groupKey": "collection",
    "groupValue": "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
    "page": 2,
    "limit": 100
  }
}'
```

当某一页返回的条目少于 `limit` 时停止。

<Tip>
  页码用法简单，但数据库仍需跳过之前的所有行，因此越靠后的页面越慢。对于大型合集或钱包，请使用游标。
</Tip>

## 游标

当你不传 `page`、`before` 或 `after` 时，API 按游标分页，并在每一页中返回一个 `cursor` 值。将它传回即可获取下一页：

```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 getAllAssetsInCollection(collection: string) {
  const assets = [];
  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: 'getAssetsByGroup',
        params: {
          groupKey: 'collection',
          groupValue: collection,
          limit: 1000,
          cursor,
        },
      }),
    });
    const { result } = await response.json();

    assets.push(...result.items);
    if (result.items.length < 1000) break;
    cursor = result.cursor;
  }

  return assets;
}
```

游标仅在结果按 `id` 排序时有效，这也是默认排序方式。

## 范围

`before` 和 `after` 接受资产 ID，并返回它们之间的资产。例如，单独使用 `after` 可以从某个已知资产 ID 之后继续：

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "searchAssets",
  "params": {
    "ownerAddress": "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
    "after": "JEGruwYE13mhX2wi2MGrPmeLiVyZtbBptmVy9vG3pXRC",
    "limit": 500
  }
}
```

范围同样要求按 `id` 排序。

## 排序

列出资产的方法接受 `sortBy`：

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
"sortBy": {
  "sortBy": "created",
  "sortDirection": "desc"
}
```

<ResponseField name="sortBy.sortBy" type="string">
  `id`（默认）、`created`、`updated`、`recent_action` 或 `none`。
</ResponseField>

<ResponseField name="sortBy.sortDirection" type="string">
  `asc`（默认）或 `desc`。
</ResponseField>

按 `id` 以外的字段排序只能配合页码使用。将其与 `cursor`、`before` 或 `after` 组合使用会返回 `-32602`。


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