getTokenAccountsByDelegate
Returns SPL Token accounts whose approved delegate matches the supplied address.
Request
JSON-RPC
{ "jsonrpc": "2.0", "id": 1, "method": "getTokenAccountsByDelegate", "params": [ "9mMBg1qaUaQdht6Q7r5T5VirRzJbNAyquKTq96FyR4UC", { "mint": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr" }, { "commitment": "finalized", "encoding": "jsonParsed" } ]}Kit (TypeScript)
import { address, createSolanaRpc } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";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);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("https://rpc.openinfra.sh"), 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(())}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| pubkey | string | Required | Pubkey of the account delegate to query, as a base-58 encoded string. |
| filter | object | Required | A JSON object with exactly one of: mint (base-58 pubkey of the specific token mint) or programId (base-58 pubkey of the Token program that owns the accounts). |
| config | object | Optional | Configuration object. See config fields below. |
config fields
| Field | Type | Default | Description |
|---|---|---|---|
| commitment | string | finalized | Commitment level: processed, confirmed, or finalized. |
| encoding | string | binary | Account-data encoding. One of base58, base64, base64+zstd, binary (deprecated), or jsonParsed. |
| minContextSlot | number | — | Minimum slot at which the request may be evaluated. |
| dataSlice | object | — | Byte slice of account data to return: offset (usize) and length (usize). Only valid with binary encodings. |
Commitment levels
| Value | Description |
|---|---|
| processed | Data from the highest slot this node has processed on the fork it currently considers best. Newest, but can change if the cluster switches forks. |
| confirmed | Data from the highest slot that at least two-thirds of active stake has directly voted to confirm. More stable than processed, weaker than finalized. |
| finalized | Data from the highest slot the cluster recognizes as finalized — maximum vote lockout and confirmed by at least two-thirds of active stake. |
Encoding formats
| Encoding | Data format | Notes |
|---|---|---|
| base64 | [data, "base64"] | Recommended. |
| base58 | [data, "base58"] | Slow. Account data must be 128 bytes or fewer. |
| base64+zstd | [data, "base64+zstd"] | Zstandard-compressed. |
| jsonParsed | {program, parsed, space} | Falls back to base64 if no parser is found. |
| binary | string | Deprecated. Same as base58 but returns data as a plain string. Use base64 instead. |
Response
{ "jsonrpc": "2.0", "result": { "context": { "apiVersion": "3.1.8", "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}RpcResponse fields
| Field | Type | Description |
|---|---|---|
| context | object | Slot and API version the node used to answer the request. |
| value | array | Array of keyed-account objects matching the delegate. |
context fields
| Field | Type | Description |
|---|---|---|
| slot | u64 | Slot at which the node evaluated the request. |
| apiVersion | string | RPC API version reported by the node. May be omitted by older nodes. |
value[] item fields
| Field | Type | Description |
|---|---|---|
| pubkey | string | Account pubkey, as a base-58 encoded string. |
| account | object | Account data object using the shared Account Data structure. |
account fields
| Field | Type | Description |
|---|---|---|
| data | string | [string, encoding] | object | Token account data. When encoding is jsonParsed, returned as { program, parsed, space }; falls back to [data, "base64"] if no parser is available. |
| 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. |
account.data (jsonParsed) fields
| Field | Type | Description |
|---|---|---|
| program | string | Name of the parser that produced the decoded data (e.g. spl-token or spl-token-2022). |
| parsed | object | Parsed SPL Token account payload. |
| 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 with raw and decimal-scaled representations. |
| delegate | string | null | Delegate pubkey, when a delegate is set. |
| state | string | Token-account state: uninitialized, initialized, or frozen. |
| isNative | bool | Whether this account wraps the native SOL mint. |
| rentExemptReserve | object | null | Rent-exempt reserve for wrapped SOL accounts. Uses the same schema as tokenAmount. |
| delegatedAmount | object | null | Amount delegated to the delegate, when present. Uses the same 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
| 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. |