# getTokenAccounts_v2

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

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

Returns all SPL token accounts for a given `mint` and/or `owner`, including token balances, mint addresses, and account metadata. At least one of `mint` or `owner` must be provided.


Reference: https://www.alchemy.com/docs/reference/alchemy-das-apis-for-solana-v2/solana-das-api-v2-endpoints/get-token-accounts-v-2

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| owner | string | No | The base-58 owner (wallet) address whose token accounts to list. Either `owner` or `mint` must be provided. |
| mint | string | No | The base-58 mint address to filter token accounts by. Either `owner` or `mint` must be provided. |
| page | integer | No | The page of results to return (1-based). |
| limit | integer | No | The maximum number of token accounts to return per page. |
| cursor | string | No | The cursor used for pagination. |
| before | string | No | Returns results before the specified cursor. |
| after | string | No | Returns results after the specified cursor. |
| options | object | No | Display and formatting options for the response. |

## Result

**Token account list** (object): A paginated list of SPL token accounts matching the query.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getTokenAccounts_v2",
  "params": [
    "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
    1,
    10
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "last_indexed_slot": 365750752,
    "total": 2,
    "limit": 10,
    "cursor": null,
    "token_accounts": [
      {
        "address": "9vGjxu6E5xQnycvY6dS8CyD2wPKa1cAaxRzHnCvGY8Bh",
        "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "owner": "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
        "amount": 125000000,
        "delegated_amount": 0,
        "frozen": false
      },
      {
        "address": "8yhX9AR6bLXJT4NqZTqTKAXY7g3vJfxV3D6h4YunKxjc",
        "mint": "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
        "owner": "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
        "amount": 5000000000,
        "delegated_amount": 0,
        "frozen": false
      }
    ]
  },
  "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": "getTokenAccounts_v2",
  "params": [
    "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
    "string",
    10,
    1,
    "string",
    "string",
    "string",
    {
      "showZeroBalance": false
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getTokenAccounts_v2',
    params: [
      '86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY',
      'string',
      10,
      1,
      'string',
      'string',
      'string',
      {showZeroBalance: false}
    ]
  })
};

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": "getTokenAccounts_v2",
    "params": ["86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY", "string", 10, 1, "string", "string", "string", { "showZeroBalance": False }]
}
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\": \"getTokenAccounts_v2\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    10,\n    1,\n    \"string\",\n    \"string\",\n    \"string\",\n    {\n      \"showZeroBalance\": false\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\": \"getTokenAccounts_v2\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    10,\n    1,\n    \"string\",\n    \"string\",\n    \"string\",\n    {\n      \"showZeroBalance\": false\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\": \"getTokenAccounts_v2\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    10,\n    1,\n    \"string\",\n    \"string\",\n    \"string\",\n    {\n      \"showZeroBalance\": false\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getTokenAccounts_v2
description: |
  Returns all SPL token accounts for a given `mint` and/or `owner`, including token balances, mint addresses, and account metadata. At least one of `mint` or `owner` must be provided.
x-compute-units: 160
x-rate-limit-cus: 200
paramStructure: by-name
params:
  - name: owner
    required: false
    description: The base-58 owner (wallet) address whose token accounts to list. Either `owner` or `mint` must be provided.
    schema:
      type: string
  - name: mint
    required: false
    description: The base-58 mint address to filter token accounts by. Either `owner` or `mint` must be provided.
    schema:
      type: string
  - name: page
    required: false
    description: The page of results to return (1-based).
    schema:
      type: integer
  - name: limit
    required: false
    description: The maximum number of token accounts to return per page.
    schema:
      type: integer
  - name: cursor
    required: false
    description: The cursor used for pagination.
    schema:
      type: string
  - name: before
    required: false
    description: Returns results before the specified cursor.
    schema:
      type: string
  - name: after
    required: false
    description: Returns results after the specified cursor.
    schema:
      type: string
  - name: options
    required: false
    description: Display and formatting options for the response.
    schema:
      title: getTokenAccounts options
      type: object
      description: Optional display flags for `getTokenAccounts`.
      properties:
        showZeroBalance:
          type: boolean
          description: If true, show accounts with empty token balances.
          default: false
examples:
  - name: getTokenAccounts_v2 example
    params:
      - name: owner
        value: 86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY
      - name: page
        value: 1
      - name: limit
        value: 10
    result:
      name: Token account list
      value:
        last_indexed_slot: 365750752
        total: 2
        limit: 10
        cursor: null
        token_accounts:
          - address: 9vGjxu6E5xQnycvY6dS8CyD2wPKa1cAaxRzHnCvGY8Bh
            mint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
            owner: 86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY
            amount: 125000000
            delegated_amount: 0
            frozen: false
          - address: 8yhX9AR6bLXJT4NqZTqTKAXY7g3vJfxV3D6h4YunKxjc
            mint: DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263
            owner: 86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY
            amount: 5000000000
            delegated_amount: 0
            frozen: false
result:
  name: Token account list
  description: A paginated list of SPL token accounts matching the query.
  schema:
    title: Token account list
    type: object
    description: A paginated list of SPL token accounts for a mint and/or owner.
    properties:
      last_indexed_slot:
        type: integer
        description: All on-chain data up to and including this slot is guaranteed to have been indexed.
      total:
        type: integer
        description: The number of results found for the request.
      limit:
        type: integer
        description: The maximum number of results requested.
      cursor:
        type: string
        description: The cursor used for pagination.
      token_accounts:
        type: array
        description: An array of token accounts.
        items:
          title: Token account
          type: object
          description: An SPL token account.
          properties:
            address:
              type: string
              description: The address of the token account.
            mint:
              type: string
              description: The address of the mint account.
            owner:
              type: string
              description: The address of the token account owner.
            amount:
              type: integer
              description: Number of tokens in the account.
            delegated_amount:
              type: integer
              description: Number of delegated tokens in the account.
            frozen:
              type: boolean
              description: Whether the account is frozen.
```
