# getTokenAccounts

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

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

Returns token accounts based on the specified filters.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| mintAddress | string | No | The mint address to filter token accounts by. |
| ownerAddress | string | No | The owner address to filter token accounts by. |
| programId | string | No | The program ID to filter accounts by. |
| commitment | enum | No | The level of commitment desired for the query. |
| minContextSlot | integer | No | The minimum slot that the request can be evaluated at. |
| dataSlice | object | No | Limit the returned account data. |
| encoding | enum | No | Encoding format for account data. |
| limit | integer | No | The maximum number of token accounts to retrieve. |
| cursor | string | No | Cursor for pagination. |

## Result

**Token accounts** (object): Returns token accounts matching the specified criteria.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getTokenAccounts",
  "params": [
    "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY"
  ],
  "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",
  "params": [
    "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
    "string",
    "string",
    "processed",
    1,
    {
      "length": 1,
      "offset": 1
    },
    "base58",
    100,
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getTokenAccounts',
    params: [
      '86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY',
      'string',
      'string',
      'processed',
      1,
      {length: 1, offset: 1},
      'base58',
      100,
      'string'
    ]
  })
};

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",
    "params": [
        "86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY",
        "string",
        "string",
        "processed",
        1,
        {
            "length": 1,
            "offset": 1
        },
        "base58",
        100,
        "string"
    ]
}
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\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    \"string\",\n    \"processed\",\n    1,\n    {\n      \"length\": 1,\n      \"offset\": 1\n    },\n    \"base58\",\n    100,\n    \"string\"\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\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    \"string\",\n    \"processed\",\n    1,\n    {\n      \"length\": 1,\n      \"offset\": 1\n    },\n    \"base58\",\n    100,\n    \"string\"\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\",\n  \"params\": [\n    \"86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY\",\n    \"string\",\n    \"string\",\n    \"processed\",\n    1,\n    {\n      \"length\": 1,\n      \"offset\": 1\n    },\n    \"base58\",\n    100,\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getTokenAccounts
description: Returns token accounts based on the specified filters.
paramStructure: by-name
params:
  - name: mintAddress
    required: false
    description: The mint address to filter token accounts by.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: ownerAddress
    required: false
    description: The owner address to filter token accounts by.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: programId
    required: false
    description: The program ID to filter accounts by.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: commitment
    required: false
    description: The level of commitment desired for the query.
    schema:
      title: Commitment Level
      type: string
      description: Configures the state commitment for querying.
      enum:
        - processed
        - confirmed
        - finalized
  - name: minContextSlot
    required: false
    description: The minimum slot that the request can be evaluated at.
    schema:
      title: Minimum Context Slot
      type: integer
      description: The minimum slot that the request can be evaluated at.
  - name: dataSlice
    required: false
    description: Limit the returned account data.
    schema:
      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.
  - name: encoding
    required: false
    description: Encoding format for account data.
    schema:
      title: Data Encoding
      type: string
      description: Encoding format for data.
      enum:
        - base58
        - base64
        - base64+zstd
        - jsonParsed
  - name: limit
    required: false
    description: The maximum number of token accounts to retrieve.
    schema:
      type: integer
      maximum: 1000
      default: 100
  - name: cursor
    required: false
    description: Cursor for pagination.
    schema:
      type: string
examples:
  - name: getTokenAccounts example
    params:
      - name: ownerAddress
        value: 86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY
result:
  name: Token accounts
  description: Returns token accounts matching the specified criteria.
  schema:
    title: Token Accounts List
    type: object
    properties:
      total:
        type: integer
        description: Total number of token accounts.
      limit:
        type: integer
        description: Number of token accounts returned.
      cursor:
        type: string
        nullable: true
        description: Cursor for pagination.
      token_accounts:
        type: array
        description: Array of token accounts.
        items:
          title: Token Account
          type: object
          properties:
            pubkey:
              title: Pubkey
              type: string
              description: The account Pubkey as a base-58 encoded string.
            account:
              title: Account Information
              type: object
              properties:
                lamports:
                  type: integer
                  description: Number of lamports assigned to this account.
                owner:
                  title: Pubkey
                  type: string
                  description: Program owner of this account.
                data:
                  title: Account Data
                  type: array
                  description: Account data in the specified encoding format.
                  items:
                    type: string
                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.
                size:
                  type: integer
                  description: The data size of the account.
```
