getTokenAccountsByDelegate — Solana RPC Method
getTokenAccountsByDelegate returns all SPL Token accounts that have approved a given address as their delegate. A delegate can transfer tokens from the account up to the approved amount.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
delegate | string | Yes | Base-58 encoded delegate public key. |
mint | string | No | Filter by specific token mint. Provide either mint or programId, not both. |
programId | string | No | Filter by token program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA for SPL Token). |
commitment | string | No | processed, confirmed, or finalized. Default: finalized. |
encoding | string | No | base64 or jsonParsed. Default: base64. |
dataSlice | object | No | {offset: usize, length: usize}. Not available with jsonParsed. |
minContextSlot | number | No | Minimum slot at which the request can be evaluated. |
You must provide either mint or programId as a filter.
Request
curl -X POST https://api.mainnet-beta.solana.com \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByDelegate",
"params": [
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
{"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
{"encoding": "jsonParsed"}
]
}'
TypeScript (@solana/kit)
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const accounts = await rpc
.getTokenAccountsByDelegate(
address("4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T"),
{ programId: address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") },
{ encoding: "jsonParsed" }
)
.send();
console.log(`Delegated accounts: ${accounts.value.length}`);
Response
{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 341200000, "apiVersion": "2.2.4" },
"value": [
{
"pubkey": "28YTZEwqtMHWrhWcvv34se7pjS7wctgqzCPB3gReCFKy",
"account": {
"data": {
"program": "spl-token",
"parsed": {
"type": "account",
"info": {
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"owner": "voter-pubkey",
"tokenAmount": { "amount": "1000000", "decimals": 6, "uiAmountString": "1" },
"delegate": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
"delegatedAmount": { "amount": "500000", "decimals": 6, "uiAmountString": "0.5" }
}
},
"space": 165
},
"executable": false,
"lamports": 2039280,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"rentEpoch": 18446744073709551615,
"space": 165
}
}
]
},
"id": 1
}
Common errors
- Must provide mint or programId — omitting both filters returns an error.
- Cannot provide both — passing both
mintandprogramIdreturns an error.
Performance
The performance depends on how many token accounts have delegated to the given address. Most addresses have few or no delegated accounts, making this a lightweight call.
FAQ
What is a token delegate?
A delegate is an address approved to transfer tokens from a token account up to a specified amount. The token owner sets the delegate and the approved amount using the SPL Token approve instruction.
How is this different from getTokenAccountsByOwner?
getTokenAccountsByOwner finds accounts owned by an address. getTokenAccountsByDelegate finds accounts that have approved an address as their delegate. Different relationships, different results.
Does this include Token-2022 accounts?
Yes, if you use the Token-2022 program ID (TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb) in the programId filter.
Why would an account have a delegate? Common use cases include DEX order books where the exchange is delegated to transfer tokens for trades, and subscription services that periodically withdraw approved amounts.
Parameters
| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
delegate | string | Yes | Base-58 encoded public key of the delegate. | — |
mint | string | No | Filter by token mint address. | — |
programId | string | No | Filter by token program ID. | — |
commitment | string | No | Commitment level: processed, confirmed, or finalized. | finalized |
encoding | string | No | Data encoding: base64, jsonParsed. | base64 |
dataSlice | object | No | Limit returned data: {offset: usize, length: usize}. Not available with jsonParsed. | — |
minContextSlot | number | No | Minimum slot at which the request can be evaluated. | — |
Updated: