> For the complete documentation index, see [llms.txt](https://docs.thornode.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thornode.io/infrastructure/fastgate-rpc/get-token-accounts-by-owner-v2.md).

# getTokenAccountsByOwnerV2

Paginated version of `getTokenAccountsByOwner` with cursor-based navigation and total count.

> **Note:** Large V1 `getTokenAccountsByOwner` queries are automatically rejected and redirected here. If you received a `-32600` error from V1, switch to this method with `limit` and `paginationKey` parameters.

## Request

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenAccountsByOwnerV2",
  "params": [
    "<walletPubkey>",
    { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
    {
      "encoding": "base64",
      "limit": 200,
      "paginationKey": null
    }
  ]
}
```

## Parameters

| Parameter          | Type    | Required | Description                                            |
| ------------------ | ------- | -------- | ------------------------------------------------------ |
| `walletPubkey`     | string  | Yes      | Base58-encoded wallet public key                       |
| filter             | object  | Yes      | One of `{ "mint": "..." }` or `{ "programId": "..." }` |
| `encoding`         | string  | No       | `"base64"` (default), `"base58"`, or `"base64+zstd"`   |
| `dataSlice`        | object  | No       | `{ offset, length }` — limit returned data bytes       |
| `limit`            | integer | No       | Page size, 1–10,000 (default 1,000)                    |
| `paginationKey`    | string  | No       | Cursor from previous response to fetch the next page   |
| `changedSinceSlot` | integer | No       | Only return accounts updated after this slot           |

### Filter Options

**By Mint** — returns only token accounts for a specific mint:

```json
{ "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" }
```

**By Program** — returns token accounts for a specific token program:

```json
{ "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" }
```

When using `mint` filter, both Token Program and Token-2022 are searched automatically.

## Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "context": { "slot": 123456789 },
    "value": [
      {
        "pubkey": "TokenAccountPubkey...",
        "account": {
          "data": ["base64-data...", "base64"],
          "executable": false,
          "lamports": 2039280,
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "rentEpoch": 361,
          "space": 165
        }
      }
    ],
    "paginationKey": "LastPubkeyInPage...",
    "totalResults": 4523
  }
}
```

| Field           | Type           | Description                                              |
| --------------- | -------------- | -------------------------------------------------------- |
| `value`         | array          | Token account objects for this page                      |
| `paginationKey` | string or null | Cursor for next page. `null` means this is the last page |
| `totalResults`  | integer        | Total number of matching token accounts                  |

## Pagination Example

**Page 1:**

```json
{
  "method": "getTokenAccountsByOwnerV2",
  "params": [
    "YourWalletPubkey...",
    { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
    { "encoding": "base64", "limit": 200 }
  ]
}
```

**Page 2 (using paginationKey from page 1):**

```json
{
  "method": "getTokenAccountsByOwnerV2",
  "params": [
    "YourWalletPubkey...",
    { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
    { "encoding": "base64", "limit": 200, "paginationKey": "LastPubkeyFromPage1..." }
  ]
}
```

## Example

```bash
curl -X POST https://rpc.thornode.io/ \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getTokenAccountsByOwnerV2",
    "params": [
      "YourWalletPubkey...",
      { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
      { "encoding": "base64", "limit": 100 }
    ]
  }'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.thornode.io/infrastructure/fastgate-rpc/get-token-accounts-by-owner-v2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
