# getTokenAccountsByDelegate

> Returns every token account that has approved a given address as its delegate.

Source: https://docs.constant-k.com/rpc/http/gettokenaccountsbydelegate/

`getTokenAccountsByDelegate` returns every SPL Token or Token-2022 account that has approved the given address as its delegate, via `Approve` or `ApproveChecked`. As with `getTokenAccountsByOwner`, the search requires narrowing with either `mint` or `programId`.

A marketplace, lending protocol or trading bot that receives delegated authority uses this to enumerate which token accounts it can move on a user's behalf.

- Transport: HTTP, JSON-RPC 2.0 `POST` to `https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY` (New York) or `https://rpc-frankfurt.constant-k.com/?api-key=YOUR_API_KEY` (Frankfurt) or `https://rpc-amsterdam.constant-k.com/?api-key=YOUR_API_KEY` (Amsterdam). The key also works as an `x-api-key` header.
- Category: Tokens
- Availability: All plans

## Parameters

`params` is a positional JSON array, in this order:

- `delegate` (string, required): Delegate address to search for, base-58 encoded.
- `filter` (object, required): Exactly one of `mint` or `programId` — the two are mutually exclusive.
  - `option 1` (object, optional)
    - `mint` (string, required): Restricts results to token accounts for this specific mint, base-58 encoded.
  - `option 2` (object, optional)
    - `programId` (string, required): Restricts results to token accounts owned by this token program, base-58 encoded.
- `config` (object, optional): Optional configuration.
  - `commitment` (string, optional, one of `finalized`, `confirmed`, `processed`, default `"finalized"`): Bank state to read the accounts from.
  - `encoding` (string, optional, one of `base58`, `base64`, `base64+zstd`, `jsonParsed`, default `"base58"`): How to encode each account's `data`. `jsonParsed` decodes the delegate and amount fields.
  - `dataSlice` (object, optional): Returns only a byte range of each account's `data`. Not valid with `jsonParsed`.
    - `offset` (integer, required)
    - `length` (integer, required)
  - `minContextSlot` (integer, optional): Minimum slot the node must have processed before answering.

## Result

- `result` (object, optional): Matching token accounts, wrapped with context. Same account shape as `getTokenAccountsByOwner`.
  - `context` (object, required)
    - `slot` (integer, optional)
    - `apiVersion` (string, optional)
  - `value` (object[], required)
    - `pubkey` (string, optional): Token account address, base-58 encoded.
    - `account` (object, optional)
      - `lamports` (integer, optional)
      - `owner` (string, optional): The token program that owns this account.
      - `executable` (boolean, optional)
      - `rentEpoch` (integer, optional)
      - `space` (integer, optional)
      - `data` (any, optional): With `jsonParsed`, `data.parsed.info` includes `mint`, `owner` (the token account's actual owner wallet), `delegate`, `delegatedAmount` and `tokenAmount`.

## Example: Find USDC accounts that delegated to a given program

Request:

```bash
curl "https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getTokenAccountsByDelegate",
    "params": [
      "GySXAguYHTkw214NbWLnaFL4g7EaBB5VwjEmoLUMKZ9m",
      { "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" },
      { "encoding": "jsonParsed" }
    ]
  }'
```

Response:

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "4.3.0-rc.0",
      "slot": 447948200
    },
    "value": [
      {
        "pubkey": "H7ZmXKqEo9U6TeQD7HqXfNfVvw9SXBWKp8sJZzXWWJmA",
        "account": {
          "data": {
            "parsed": {
              "info": {
                "isNative": false,
                "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
                "owner": "8YrUCWz386tNvsyBGony4pHf2KYawB2Lsmyj9koG2Zea",
                "state": "initialized",
                "delegate": "GySXAguYHTkw214NbWLnaFL4g7EaBB5VwjEmoLUMKZ9m",
                "delegatedAmount": {
                  "amount": "5000000000",
                  "decimals": 6,
                  "uiAmount": 5000,
                  "uiAmountString": "5000"
                },
                "tokenAmount": {
                  "amount": "5000000000",
                  "decimals": 6,
                  "uiAmount": 5000,
                  "uiAmountString": "5000"
                }
              },
              "type": "account"
            },
            "program": "spl-token",
            "space": 165
          },
          "executable": false,
          "lamports": 2039280,
          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
          "rentEpoch": 18446744073709552000,
          "space": 165
        }
      }
    ]
  },
  "id": 1
}
```

## Notes

- `owner` in `data.parsed.info` is the token account's controlling wallet, not the delegate searched for; the delegate appears only in `delegate` and `delegatedAmount`.
- An empty `value` array means no token account currently has this address approved as a delegate; this is a common result, since delegation is the exception for most token accounts.
- A token account only ever has one active delegate at a time; approving a new delegate replaces the previous one.

