# getTokenAccountsByDelegate

> 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 delegated to the provided account.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Delegate Pubkey | string | Yes | The Pubkey of the account delegate to query. |
| Token filter | object | No | A filter object containing either the Mint Pubkey or the Token program Pubkey. |
| Configuration | object | No | Optional configuration object containing additional settings. |

## Result

**Token accounts** (object[]): An array of JSON objects representing the token accounts delegated to the specified Pubkey.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getTokenAccountsByDelegate",
  "params": [
    "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
    {
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    }
  ],
  "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": "getTokenAccountsByDelegate",
  "params": [
    "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
    {
      "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
    },
    {
      "commitment": "processed",
      "minContextSlot": 1,
      "dataSlice": {
        "length": 1,
        "offset": 1
      },
      "encoding": "base58"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getTokenAccountsByDelegate',
    params: [
      '4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T',
      {programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'},
      {
        commitment: 'processed',
        minContextSlot: 1,
        dataSlice: {length: 1, offset: 1},
        encoding: 'base58'
      }
    ]
  })
};

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": "getTokenAccountsByDelegate",
    "params": [
        "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
        { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
        {
            "commitment": "processed",
            "minContextSlot": 1,
            "dataSlice": {
                "length": 1,
                "offset": 1
            },
            "encoding": "base58"
        }
    ]
}
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\": \"getTokenAccountsByDelegate\",\n  \"params\": [\n    \"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      },\n      \"encoding\": \"base58\"\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\": \"getTokenAccountsByDelegate\",\n  \"params\": [\n    \"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      },\n      \"encoding\": \"base58\"\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\": \"getTokenAccountsByDelegate\",\n  \"params\": [\n    \"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T\",\n    {\n      \"programId\": \"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"\n    },\n    {\n      \"commitment\": \"processed\",\n      \"minContextSlot\": 1,\n      \"dataSlice\": {\n        \"length\": 1,\n        \"offset\": 1\n      },\n      \"encoding\": \"base58\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getTokenAccountsByDelegate
description: Returns all SPL Token accounts delegated to the provided account.
params:
  - name: Delegate Pubkey
    required: true
    description: The Pubkey of the account delegate to query.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: Token filter
    required: false
    description: A filter object containing either the Mint Pubkey or the Token program Pubkey.
    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.
  - name: Configuration
    required: false
    description: Optional configuration object containing additional settings.
    schema:
      title: GetTokenAccountsByDelegate Configuration
      type: object
      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.
        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
examples:
  - name: getTokenAccountsByDelegate example
    params:
      - name: Delegate Pubkey
        value: 4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T
      - name: Token filter
        value:
          programId: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
result:
  name: Token accounts
  description: An array of JSON objects representing the token accounts delegated to the specified Pubkey.
  schema:
    type: array
    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.
```
