> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# getTokenAccountsByDelegate

> Returns SPL Token accounts whose approved delegate matches the supplied address.

<Info>
  **Source**

  [`get_token_accounts_by_delegate`](https://github.com/anza-xyz/agave/blob/v4.3.2/rpc/src/rpc.rs#L2197)
</Info>

<Warning>
  The public mainnet, devnet, and testnet endpoints turn this method off. They
  answer every request with HTTP `429` "Too many requests for a specific RPC
  call", which waiting does not clear. Call it on an RPC provider that serves
  it, or on a local network at `http://localhost:8899`, as the examples on this
  page do: `solana-test-validator`, or Surfpool started with `--offline` (a
  Surfpool that forks a public cluster forwards this method there and gets the
  same `429`). Replace the example addresses with accounts on your network.
</Warning>

<RequestExample>
  ```bash cURL
  curl http://localhost:8899 -s -X POST \
    -H "Content-Type: application/json" \
    -d '
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getTokenAccountsByDelegate",
      "params": [
        "9mMBg1qaUaQdht6Q7r5T5VirRzJbNAyquKTq96FyR4UC",
        {
          "mint": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"
        },
        {
          "commitment": "finalized",
          "encoding": "jsonParsed"
        }
      ]
    }
  '
  ```

  ```ts Kit
  import { address, createSolanaRpc } from "@solana/kit";

  const rpc_url = "http://localhost:8899";
  const rpc = createSolanaRpc(rpc_url);

  let delegate = address("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");

  let tokenProgram = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

  let tokenAccByDelegate = await rpc
    .getTokenAccountsByDelegate(
      delegate,
      { programId: tokenProgram },
      {
        commitment: "finalized",
        encoding: "jsonParsed"
      }
    )
    .send();

  console.log(tokenAccByDelegate);
  ```

  ```rs Rust
  use anyhow::Result;
  use solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::TokenAccountsFilter};
  use solana_commitment_config::CommitmentConfig;
  use solana_sdk::pubkey;

  #[tokio::main]
  async fn main() -> Result<()> {
      let client = RpcClient::new_with_commitment(
          String::from("http://localhost:8899"),
          CommitmentConfig::confirmed(),
      );

      let delegate = pubkey!("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");

      let token_program = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

      let token_acc_by_del = client
          .get_token_accounts_by_delegate_with_commitment(
              &delegate,
              TokenAccountsFilter::ProgramId(token_program),
              CommitmentConfig::finalized(),
          )
          .await?;

      println!("{:#?}", token_acc_by_del);

      Ok(())
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response
  {
    "jsonrpc": "2.0",
    "result": {
      "context": { "apiVersion": "4.3.2", "slot": 1114 },
      "value": [
        {
          "pubkey": "28YTZEwqtMHWrhWcvv34se7pjS7wctgqzCPB3gReCFKp",
          "account": {
            "data": {
              "program": "spl-token",
              "parsed": {
                "info": {
                  "tokenAmount": {
                    "amount": "1",
                    "decimals": 1,
                    "uiAmount": 0.1,
                    "uiAmountString": "0.1"
                  },
                  "delegate": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
                  "delegatedAmount": {
                    "amount": "1",
                    "decimals": 1,
                    "uiAmount": 0.1,
                    "uiAmountString": "0.1"
                  },
                  "state": "initialized",
                  "isNative": false,
                  "mint": "3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E",
                  "owner": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"
                },
                "type": "account"
              },
              "space": 165
            },
            "executable": false,
            "lamports": 1726080,
            "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
            "rentEpoch": 4,
            "space": 165
          }
        }
      ]
    },
    "id": 1
  }
  ```
</ResponseExample>

## Parameters

<ParamField body="pubkey" type="string" required>
  Pubkey of account delegate to query, as base-58 encoded string
</ParamField>

<ParamField body="token account filter" type="object" required>
  A JSON object with one of the following fields:

  <Expandable title="properties" defaultOpen>
    <ParamField body="mint" type="string">
      Pubkey of the specific token Mint to limit accounts to, as base-58 encoded
      string; or

      ```json Example
      { "mint": "So11111111111111111111111111111111111111112" }
      ```
    </ParamField>

    <ParamField body="programId" type="string">
      Pubkey of the Token program that owns the accounts, as base-58 encoded string
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="config" type="object">
  Configuration object containing the following fields:

  <Expandable title="properties" defaultOpen>
    <ParamField body="commitment" type="string" default="finalized">
      Values: `processed`, `confirmed`, `finalized`

      Solana RPC uses the following commitment levels:

      | Value       | Description                                                                                                                                                                               |
      | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `processed` | Return data from the highest slot this node has processed. This is the newest view, but the block can still be skipped.                                                                   |
      | `confirmed` | Return data from the same slot as `finalized`. Kept for compatibility and planned for removal in a later release.                                                                         |
      | `finalized` | Return data from the highest slot with a finalization certificate, from votes by 80% of stake in one round or 60% of stake in each of two rounds. This is the strongest commitment level. |
    </ParamField>

    <ParamField body="minContextSlot" type="number">
      The minimum slot that the request can be evaluated at

      ```json Example
      { "minContextSlot": 341197000 }
      ```
    </ParamField>

    <ParamField body="dataSlice" type="object">
      Request a slice of the account's data.

      | Field    | Type    | Description                                           |
      | -------- | ------- | ----------------------------------------------------- |
      | `offset` | `usize` | Byte offset from which to start reading account data. |
      | `length` | `usize` | Number of bytes to return.                            |

      ```json Example
      { "offset": 0, "length": 32 }
      ```

      <Info>
        Data slicing is only available for `base58`, `base64`, `base64+zstd`, and
        `binary` encodings.
      </Info>

      <Info>
        Use `encoding: "jsonParsed"` if you want the parsed token account structure
        shown in the response example below.
      </Info>
    </ParamField>

    <ParamField body="encoding" type="string" default="binary">
      Values: `base58`, `base64`, `base64+zstd`, `binary`, `jsonParsed`

      Encoding format for account data.

      | Encoding      | Data format                | Notes                                                                                                                                                                                                                    |
      | ------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
      | `base64`      | `[data, "base64"]`         | Recommended                                                                                                                                                                                                              |
      | `base58`      | `[data, "base58"]`         | Slow. The account's data field must be 128 bytes or fewer                                                                                                                                                                |
      | `base64+zstd` | `[data, "base64+zstd"]`    | [Zstandard](https://github.com/facebook/zstd) compressed                                                                                                                                                                |
      | `jsonParsed`  | `{program, parsed, space}` | Falls back to `[data, "base64"]` if no parser found                                                                                                                                                                      |
      | `binary`      | `string`                   | Deprecated. Legacy encoding retained for backwards compatibility. Same base58 encoding as `base58` with the same 128-byte data field limit, but returns data as a plain string instead of an array. Use `base64` instead |

      If you use `jsonParsed`, this method returns the token-account wrapper
      `{program, parsed, space}`. The `program` field identifies the token parser that
      produced `parsed`.

      | `program` value  | Parsed account type     |
      | ---------------- | ----------------------- |
      | `spl-token`      | SPL Token accounts      |
      | `spl-token-2022` | SPL Token 2022 accounts |

      The nested `parsed` payload on this page uses the SPL Token account form
      documented below.

      The nested `account` field uses the shared
      [Account Data](/developers/docs/rpc/json-structures#account-data) wrapper, and
      `tokenAmount` uses the same amount fields documented in
      [Token Balances](/developers/docs/rpc/json-structures#token-balances).
    </ParamField>
  </Expandable>
</ParamField>

## Result

<ResponseField name="result" type="object">
  RpcResponse object containing:

  <Expandable title="properties" defaultOpen>
    <ResponseField name="context" type="object">
      Slot and API version the node used to answer this request.

      | Field        | Type     | Description                                                                     |
      | ------------ | -------- | ------------------------------------------------------------------------------- |
      | `slot`       | `u64`    | Slot at which the node evaluated this request.                                  |
      | `apiVersion` | `string` | RPC API version reported by the node. This field may be omitted by older nodes. |
    </ResponseField>

    <ResponseField name="value" type="array">
      Array of keyed-account objects with the following fields:

      | Field     | Type     | Description                                                                                            |
      | --------- | -------- | ------------------------------------------------------------------------------------------------------ |
      | `pubkey`  | `string` | Account pubkey, as a base-58 encoded string.                                                           |
      | `account` | `object` | Account data object. Uses the shared [Account Data](/developers/docs/rpc/json-structures#account-data) structure. |

      | Field        | Type                                     | Description                                                                                                                                                                                                               |
      | ------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `data`       | `string \| [string, encoding] \| object` | Token account data. Binary forms depend on the `encoding` parameter. When `encoding` is `jsonParsed`, this field is `{program, parsed, space}`; if no parser is available, the RPC node falls back to `[data, "base64"]`. |
      | `executable` | `bool`                                   | Whether the account contains a program and is therefore read-only.                                                                                                                                                        |
      | `lamports`   | `u64`                                    | Lamports assigned to the account.                                                                                                                                                                                         |
      | `owner`      | `string`                                 | Program owner pubkey, as a base-58 encoded string.                                                                                                                                                                        |
      | `rentEpoch`  | `u64`                                    | Next epoch at which the account owes rent.                                                                                                                                                                                |
      | `space`      | `u64 \| null`                            | Account data size in bytes. Current Solana RPC responses populate this field for encoded account responses.                                                                                                               |

      When `account.data` is returned as an object, it contains:

      | Field     | Type     | Description                                                                                                 |
      | --------- | -------- | ----------------------------------------------------------------------------------------------------------- |
      | `program` | `string` | Name of the parser that produced the decoded token-account data.                                            |
      | `parsed`  | `object` | Parsed SPL Token account payload. For this method, this field uses the token-account form documented below. |
      | `space`   | `u64`    | Account data size in bytes.                                                                                 |

      **`parsed` fields**

      | Field  | Type     | Description                       |
      | ------ | -------- | --------------------------------- |
      | `type` | `string` | Always `account` for this method. |
      | `info` | `object` | Parsed SPL Token account fields.  |

      **`parsed.info` fields**

      | Field               | Type             | Description                                                                                                                       |
      | ------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------- |
      | `mint`              | `string`         | Token mint pubkey, as a base-58 encoded string.                                                                                   |
      | `owner`             | `string`         | Token-account owner pubkey, as a base-58 encoded string.                                                                          |
      | `tokenAmount`       | `object`         | Token amount object with raw and decimal-scaled representations.                                                                  |
      | `delegate`          | `string \| null` | Delegate pubkey, when a delegate is set.                                                                                          |
      | `state`             | `string`         | Token-account state. The value is `uninitialized`, `initialized`, or `frozen`.                                                    |
      | `isNative`          | `bool`           | Whether this account wraps the native SOL mint.                                                                                   |
      | `rentExemptReserve` | `object \| null` | Rent-exempt reserve amount for wrapped SOL accounts, when present. Uses the same token-amount schema as `tokenAmount`.            |
      | `delegatedAmount`   | `object \| null` | Amount delegated to `delegate`, when present. Uses the same token-amount schema as `tokenAmount`.                                 |
      | `closeAuthority`    | `string \| null` | Close-authority pubkey, when present.                                                                                             |
      | `extensions`        | `array`          | Parsed SPL Token 2022 extension entries. Each element has an `extension` discriminator and an extension-specific `state` payload. |

      **`tokenAmount` fields**

      This nested amount object uses the same numeric fields documented in
      [Token Balances](/developers/docs/rpc/json-structures#token-balances).

      | Field            | Type             | Description                                                                                |
      | ---------------- | ---------------- | ------------------------------------------------------------------------------------------ |
      | `uiAmount`       | `number \| null` | Decimal-scaled amount as a floating-point number. Deprecated in favor of `uiAmountString`. |
      | `decimals`       | `u8`             | Number of decimal places configured on the mint.                                           |
      | `amount`         | `string`         | Raw token amount, as a base-10 integer string.                                             |
      | `uiAmountString` | `string`         | Decimal-scaled amount as a string.                                                         |
    </ResponseField>
  </Expandable>
</ResponseField>
