# getTokenAccountsByOwnerV2

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://solana-mainnet.g.alchemy.com/v2/{apiKey}

Paginated variant of `getTokenAccountsByOwner`. Reach for this when a wallet holds enough token accounts that the single-response version times out or runs into memory limits: indexing every SPL Token or Token-2022 account for an active wallet, backing a portfolio dashboard, or keeping a downstream cache aligned with recent on-chain changes.

Requests accept the same `commitment`, `minContextSlot`, `encoding`, and `dataSlice` fields as `getTokenAccountsByOwner`, with three additions on the configuration object:

* `limit` bounds a single page to between 1 and 10,000 token accounts (default 1,000).
* `paginationKey` is the base-58 cursor returned by the previous page; omit it on the first request.
* `changedSinceSlot` restricts the page to token accounts written at or after the given slot, so you can keep a downstream index in sync without re-scanning the wallet's full holdings.

The filter requirement carries over from V1: supply either a `mint` (specific SPL Token or Token-2022 mint) or a `programId` (SPL Token or Token-2022 program). Querying every token type for a wallet with no filter is not supported.

Keep paging while `paginationKey` is a string. It only turns `null` once the server has no more token accounts to hand out; a page shorter than `limit` on its own does not mean the walk is finished, because filters can drop accounts server-side before the page ships.

Set `withContext: true` on the configuration object to receive the wrapped Solana RPC shape: a `context` object (with at minimum the `slot` the node evaluated the request at, plus `apiVersion` when the node reports one) beside a `value` payload holding `accounts` and `paginationKey`. Leave `withContext` unset or `false` and `value` is returned directly as the token-account array with `paginationKey` on `result` and no `context` sibling. Every other aspect of the response is identical between the two shapes.


Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-token-accounts-by-owner-v-2

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Token owner Pubkey | string | Yes | The Pubkey of the account owner to query. |
| Token filter | object | Yes | A filter object containing either the Mint Pubkey or the Token program Pubkey. Supply exactly one; querying every token type for a wallet with no filter is not supported. |
| Configuration | object | No | Optional configuration object. Accepts every field `getTokenAccountsByOwner` accepts, with the pagination and incremental-update fields (`limit`, `paginationKey`, `changedSinceSlot`) and the `withContext` response-shape toggle layered on top. |

## Result

**Token accounts page** (object): A page of token accounts (up to `limit`) alongside the cursor for the next request. When the request sets `withContext: true`, the same page is placed inside a `{context, value}` envelope instead of being returned directly on `result`.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getTokenAccountsByOwnerV2",
  "params": [
    "GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q",
    {
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    },
    {
      "encoding": "jsonParsed",
      "limit": 2
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "value": [
      {
        "pubkey": "14PGqS2rWvYXGVTjUJZXaAL3KQcjPKki7SbBWfuZF7Ua",
        "account": {
          "lamports": 2039280,
          "data": {
            "program": "spl-token",
            "parsed": {
              "type": "account",
              "info": {
                "mint": "3uLVAK5waVjVjt1CyCitfbLXb3pKBTzG2vEagifTyxPN",
                "owner": "GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q",
                "tokenAmount": {
                  "amount": "1",
                  "decimals": 0,
                  "uiAmount": 1,
                  "uiAmountString": "1"
                },
                "state": "initialized",
                "isNative": false
              }
            },
            "space": 165
          },
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "executable": false,
          "rentEpoch": 18446744073709552000,
          "space": 165
        }
      },
      {
        "pubkey": "6SpaWxfEvVL3DmqGA2sDiRHsK2yMUYARAcJU6jcCUrD",
        "account": {
          "lamports": 2039280,
          "data": {
            "program": "spl-token",
            "parsed": {
              "type": "account",
              "info": {
                "mint": "ARt4N4WY4PEdYUuBG7qENwuYSSiQUqP1RXFiahhwfzH9",
                "owner": "GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q",
                "tokenAmount": {
                  "amount": "552960556809595",
                  "decimals": 9,
                  "uiAmount": 552960.556809595,
                  "uiAmountString": "552960.556809595"
                },
                "state": "initialized",
                "isNative": false
              }
            },
            "space": 165
          },
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "executable": false,
          "rentEpoch": 18446744073709552000,
          "space": 165
        }
      }
    ],
    "paginationKey": "6SpaWxfEvVL3DmqGA2sDiRHsK2yMUYARAcJU6jcCUrD"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenAccountsByOwnerV2",
  "params": [
    "GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q",
    {
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    },
    {
      "encoding": "jsonParsed",
      "limit": 2
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getTokenAccountsByOwnerV2',
    params: [
      'GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q',
      {programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'},
      {encoding: 'jsonParsed', limit: 2}
    ]
  })
};

fetch('https://solana-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getTokenAccountsByOwnerV2",
    "params": [
        "GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q",
        { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
        {
            "encoding": "jsonParsed",
            "limit": 2
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getTokenAccountsByOwnerV2\",\n  \"params\": [\n    \"GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"encoding\": \"jsonParsed\",\n      \"limit\": 2\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getTokenAccountsByOwnerV2\",\n  \"params\": [\n    \"GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"encoding\": \"jsonParsed\",\n      \"limit\": 2\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getTokenAccountsByOwnerV2\",\n  \"params\": [\n    \"GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"encoding\": \"jsonParsed\",\n      \"limit\": 2\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: getTokenAccountsByOwnerV2
description: |
  Paginated variant of `getTokenAccountsByOwner`. Reach for this when a wallet holds enough token accounts that the single-response version times out or runs into memory limits: indexing every SPL Token or Token-2022 account for an active wallet, backing a portfolio dashboard, or keeping a downstream cache aligned with recent on-chain changes.

  Requests accept the same `commitment`, `minContextSlot`, `encoding`, and `dataSlice` fields as `getTokenAccountsByOwner`, with three additions on the configuration object:

  * `limit` bounds a single page to between 1 and 10,000 token accounts (default 1,000).
  * `paginationKey` is the base-58 cursor returned by the previous page; omit it on the first request.
  * `changedSinceSlot` restricts the page to token accounts written at or after the given slot, so you can keep a downstream index in sync without re-scanning the wallet's full holdings.

  The filter requirement carries over from V1: supply either a `mint` (specific SPL Token or Token-2022 mint) or a `programId` (SPL Token or Token-2022 program). Querying every token type for a wallet with no filter is not supported.

  Keep paging while `paginationKey` is a string. It only turns `null` once the server has no more token accounts to hand out; a page shorter than `limit` on its own does not mean the walk is finished, because filters can drop accounts server-side before the page ships.

  Set `withContext: true` on the configuration object to receive the wrapped Solana RPC shape: a `context` object (with at minimum the `slot` the node evaluated the request at, plus `apiVersion` when the node reports one) beside a `value` payload holding `accounts` and `paginationKey`. Leave `withContext` unset or `false` and `value` is returned directly as the token-account array with `paginationKey` on `result` and no `context` sibling. Every other aspect of the response is identical between the two shapes.
x-compute-units: 10
params:
  - name: Token owner Pubkey
    required: true
    description: The Pubkey of the account owner to query.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: Token filter
    required: true
    description: A filter object containing either the Mint Pubkey or the Token program Pubkey. Supply exactly one; querying every token type for a wallet with no filter is not supported.
    schema:
      type: object
      properties:
        mint:
          title: Pubkey
          type: string
          description: The Pubkey of the specific token Mint to limit accounts to.
        programId:
          title: Pubkey
          type: string
          description: The Pubkey of the Token program that owns the accounts. Use `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA` for SPL Token or `TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb` for Token-2022.
  - name: Configuration
    required: false
    description: Optional configuration object. Accepts every field `getTokenAccountsByOwner` accepts, with the pagination and incremental-update fields (`limit`, `paginationKey`, `changedSinceSlot`) and the `withContext` response-shape toggle layered on top.
    schema:
      title: GetTokenAccountsByOwnerV2 Configuration
      type: object
      description: Options for a single `getTokenAccountsByOwnerV2` request. Every field that `GetTokenAccountsByOwnerConfig` accepts is honored here; the pagination and incremental-update fields (`limit`, `paginationKey`, `changedSinceSlot`) and the `withContext` response-shape toggle sit alongside them.
      properties:
        commitment:
          title: Commitment Level
          type: string
          description: Configures the state commitment for querying.
          enum:
            - processed
            - confirmed
            - finalized
        minContextSlot:
          title: Minimum Context Slot
          type: integer
          description: The minimum slot that the request can be evaluated at.
        withContext:
          type: boolean
          description: 'Set to `true` to receive the wrapped Solana RPC shape: a `context` object (at minimum a `slot` field, plus `apiVersion` when the node reports one) beside a `value` object holding `accounts` and `paginationKey`. Leave unset or set to `false` and those two fields sit at the top of `result` with no `context` sibling and `value` returned as the token-account array directly. Filters, page size, and cursor behavior are identical either way — only the outer JSON shape changes.'
        dataSlice:
          title: Data Slice
          type: object
          properties:
            length:
              type: integer
              description: Number of bytes to return.
            offset:
              type: integer
              description: Byte offset from which to start reading.
        encoding:
          description: Encoding format for account data.
          title: Data Encoding
          type: string
          enum:
            - base58
            - base64
            - base64+zstd
            - jsonParsed
        limit:
          type: integer
          minimum: 1
          maximum: 10000
          default: 1000
          description: Upper bound on the number of token accounts returned per page (1-10,000). Server-side filtering can shrink a page below `limit` without meaning the walk is finished — keep paging until `paginationKey` comes back `null`.
        paginationKey:
          type: string
          description: Cursor for the next page, base-58 encoded. Take the value from the previous response's `paginationKey`; leave this field out on the first call.
        changedSinceSlot:
          type: integer
          minimum: 0
          description: Restrict the page to token accounts written at or after this slot. Useful for keeping a downstream portfolio index in sync without re-scanning the wallet's full token holdings.
examples:
  - name: getTokenAccountsByOwnerV2 example
    params:
      - name: Token owner Pubkey
        value: GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q
      - name: Token filter
        value:
          programId: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
      - name: Configuration
        value:
          encoding: jsonParsed
          limit: 2
    result:
      name: Token accounts page
      value:
        value:
          - pubkey: 14PGqS2rWvYXGVTjUJZXaAL3KQcjPKki7SbBWfuZF7Ua
            account:
              lamports: 2039280
              data:
                program: spl-token
                parsed:
                  type: account
                  info:
                    mint: 3uLVAK5waVjVjt1CyCitfbLXb3pKBTzG2vEagifTyxPN
                    owner: GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q
                    tokenAmount:
                      amount: '1'
                      decimals: 0
                      uiAmount: 1
                      uiAmountString: '1'
                    state: initialized
                    isNative: false
                space: 165
              owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
              executable: false
              rentEpoch: 18446744073709552000
              space: 165
          - pubkey: 6SpaWxfEvVL3DmqGA2sDiRHsK2yMUYARAcJU6jcCUrD
            account:
              lamports: 2039280
              data:
                program: spl-token
                parsed:
                  type: account
                  info:
                    mint: ARt4N4WY4PEdYUuBG7qENwuYSSiQUqP1RXFiahhwfzH9
                    owner: GwsPP9HHhCvEQeu3HTFzsVL6DEtnnYw4ALEtA3fMBC9Q
                    tokenAmount:
                      amount: '552960556809595'
                      decimals: 9
                      uiAmount: 552960.556809595
                      uiAmountString: '552960.556809595'
                    state: initialized
                    isNative: false
                space: 165
              owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
              executable: false
              rentEpoch: 18446744073709552000
              space: 165
        paginationKey: 6SpaWxfEvVL3DmqGA2sDiRHsK2yMUYARAcJU6jcCUrD
result:
  name: Token accounts page
  description: 'A page of token accounts (up to `limit`) alongside the cursor for the next request. When the request sets `withContext: true`, the same page is placed inside a `{context, value}` envelope instead of being returned directly on `result`.'
  schema:
    title: Token Accounts By Owner V2 Result
    description: 'Shape of the `result` object. With `withContext` unset or `false`, the page''s `accounts` and `paginationKey` are returned at the top level, with `accounts` renamed to `value` and given as the token-account array directly. With `withContext: true`, the same page is placed under `value` as an object (`accounts` + `paginationKey`), and a `context` sibling carries the slot the node used to build the response.'
    oneOf:
      - type: object
        title: without withContext
        description: 'Direct shape returned when the request omits `withContext` or sends `withContext: false`. Matches the familiar `getTokenAccountsByOwner` layout, with the pagination cursor added on `result`.'
        properties:
          value:
            type: array
            description: Token accounts for the current page, decoded in the requested `encoding` (defaults to `jsonParsed`).
            items:
              title: Parsed Token Account
              type: object
              description: A single SPL Token or Token-2022 account with its data decoded in `jsonParsed` form.
              properties:
                pubkey:
                  title: Pubkey
                  type: string
                  description: The token account Pubkey as a base-58 encoded string.
                account:
                  title: Parsed Token Account Info
                  type: object
                  description: Account metadata plus the `jsonParsed` token account payload.
                  properties:
                    lamports:
                      type: integer
                      description: Number of lamports assigned to this account.
                    owner:
                      title: Pubkey
                      type: string
                      description: The token program that owns this account (SPL Token or Token-2022).
                    executable:
                      type: boolean
                      description: Indicates if the account contains a program.
                    rentEpoch:
                      type: integer
                      description: The epoch at which this account will next owe rent.
                    space:
                      type: integer
                      description: On-chain data size in bytes.
                    data:
                      title: Parsed SPL Token Account Data
                      type: object
                      description: '`jsonParsed` decoding of a token account''s on-chain data. The outer envelope carries the parser identity; the actual account fields live under `parsed.info`.'
                      properties:
                        program:
                          type: string
                          description: The program the parser used to decode this account (`spl-token` or `spl-token-2022`).
                        space:
                          type: integer
                          description: On-chain data size in bytes.
                        parsed:
                          type: object
                          description: The parsed account payload.
                          properties:
                            type:
                              type: string
                              description: The parsed record type (e.g., `account`).
                            info:
                              title: Parsed SPL Token Account Info
                              type: object
                              description: '`jsonParsed` decoding of an SPL Token or Token-2022 account''s data.'
                              properties:
                                isNative:
                                  type: boolean
                                  description: '`true` when this token account is the native SOL mint wrapper.'
                                mint:
                                  title: Pubkey
                                  type: string
                                  description: The mint associated with this token account.
                                owner:
                                  title: Pubkey
                                  type: string
                                  description: The wallet that owns this token account.
                                state:
                                  type: string
                                  description: Account state, typically `initialized`, `uninitialized`, or `frozen`.
                                tokenAmount:
                                  title: Token Balance
                                  type: object
                                  description: The token balance held by this account.
                                  properties:
                                    amount:
                                      type: string
                                      description: The raw balance without decimals, a string representation of u64.
                                    decimals:
                                      type: integer
                                      description: Number of base-10 digits to the right of the decimal place.
                                    uiAmount:
                                      type: number
                                      nullable: true
                                      description: The balance, using mint-prescribed decimals. **DEPRECATED**
                                    uiAmountString:
                                      type: string
                                      description: The balance as a string, using mint-prescribed decimals.
          paginationKey:
            type: string
            nullable: true
            description: Cursor to feed into the next request, base-58 encoded. `null` only when the server confirms the end of pagination — a short page on its own does not mean the walk is finished.
      - type: object
        title: with withContext
        description: 'Envelope returned when the request has `withContext: true`.'
        required:
          - context
          - value
        properties:
          context:
            type: object
            description: Node metadata for the moment this response was built.
            properties:
              slot:
                type: integer
                description: Slot at which the node built this response.
              apiVersion:
                type: string
                description: RPC API version when available.
          value:
            title: Token Accounts By Owner V2 Page
            type: object
            description: A single page of token accounts plus the cursor for the next one. These fields sit directly on `result`, or under `result.value`, depending on the request's `withContext` flag.
            properties:
              accounts:
                type: array
                description: Token accounts owned by the wallet that fell into this page.
                items:
                  title: Parsed Token Account
                  type: object
                  description: A single SPL Token or Token-2022 account with its data decoded in `jsonParsed` form.
                  properties:
                    pubkey:
                      title: Pubkey
                      type: string
                      description: The token account Pubkey as a base-58 encoded string.
                    account:
                      title: Parsed Token Account Info
                      type: object
                      description: Account metadata plus the `jsonParsed` token account payload.
                      properties:
                        lamports:
                          type: integer
                          description: Number of lamports assigned to this account.
                        owner:
                          title: Pubkey
                          type: string
                          description: The token program that owns this account (SPL Token or Token-2022).
                        executable:
                          type: boolean
                          description: Indicates if the account contains a program.
                        rentEpoch:
                          type: integer
                          description: The epoch at which this account will next owe rent.
                        space:
                          type: integer
                          description: On-chain data size in bytes.
                        data:
                          title: Parsed SPL Token Account Data
                          type: object
                          description: '`jsonParsed` decoding of a token account''s on-chain data. The outer envelope carries the parser identity; the actual account fields live under `parsed.info`.'
                          properties:
                            program:
                              type: string
                              description: The program the parser used to decode this account (`spl-token` or `spl-token-2022`).
                            space:
                              type: integer
                              description: On-chain data size in bytes.
                            parsed:
                              type: object
                              description: The parsed account payload.
                              properties:
                                type:
                                  type: string
                                  description: The parsed record type (e.g., `account`).
                                info:
                                  title: Parsed SPL Token Account Info
                                  type: object
                                  description: '`jsonParsed` decoding of an SPL Token or Token-2022 account''s data.'
                                  properties:
                                    isNative:
                                      type: boolean
                                      description: '`true` when this token account is the native SOL mint wrapper.'
                                    mint:
                                      title: Pubkey
                                      type: string
                                      description: The mint associated with this token account.
                                    owner:
                                      title: Pubkey
                                      type: string
                                      description: The wallet that owns this token account.
                                    state:
                                      type: string
                                      description: Account state, typically `initialized`, `uninitialized`, or `frozen`.
                                    tokenAmount:
                                      title: Token Balance
                                      type: object
                                      description: The token balance held by this account.
                                      properties:
                                        amount:
                                          type: string
                                          description: The raw balance without decimals, a string representation of u64.
                                        decimals:
                                          type: integer
                                          description: Number of base-10 digits to the right of the decimal place.
                                        uiAmount:
                                          type: number
                                          nullable: true
                                          description: The balance, using mint-prescribed decimals. **DEPRECATED**
                                        uiAmountString:
                                          type: string
                                          description: The balance as a string, using mint-prescribed decimals.
              paginationKey:
                type: string
                nullable: true
                description: Cursor to feed into the next request, base-58 encoded. Turns to `null` once the server confirms there are no further token accounts to hand out. A page shorter than the requested `limit` does not by itself mean the walk is done — keep calling until this field is `null`.
```
