getTokenAccountsByDelegate
Returns all SPL Token accounts that have been delegated to a specified address. Token delegation allows an account owner to grant spending authority to another address up to a certain amount. This method is useful for querying which token accounts have approved a specific address to spend tokens on their behalf, which is common in DeFi protocols that use approval-based token transfers.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | string | Yes | Base-58 encoded public key of the delegate to query |
| 2 | object | Yes | Filter object -- must contain either mint or programId |
| 3 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
mint | string | Filter by SPL Token mint address (base-58) |
programId | string | Filter by SPL Token program ID (base-58) |
encoding | string | Data encoding: base64, base64+zstd, or jsonParsed |
commitment | string | Commitment level: processed, confirmed, or finalized |
dataSlice | object | Limit returned data: { offset: number, length: number } |
minContextSlot | number | Minimum slot at which the request can be evaluated |
Response
Returns an RpcResponse with an array of token account objects:
| Field | Type | Description |
|---|---|---|
context.slot | u64 | The slot at which the value was read |
value[].pubkey | string | Token account address (base-58) |
value[].account.data | object | Token account data in the requested encoding |
value[].account.lamports | u64 | Lamports in the token account |
value[].account.owner | string | Token program ID |
Code Examples
cURL
curl http://88.216.36.108:7999 -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByDelegate",
"params": [
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
{ "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
{ "encoding": "jsonParsed" }
]
}'TypeScript
const response = await fetch("http://88.216.36.108:7999", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getTokenAccountsByDelegate",
params: [
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
{ programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
{ encoding: "jsonParsed" }
]
}),
});
const { result } = await response.json();
console.log("Delegated accounts:", result.value.length);Python
import requests
response = requests.post("http://88.216.36.108:7999", json={
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByDelegate",
"params": [
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
{"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
{"encoding": "jsonParsed"}
]
})
result = response.json()["result"]
print(f"Delegated accounts: {len(result['value'])}")Rust
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let res = client.post("http://88.216.36.108:7999")
.json(&json!({
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByDelegate",
"params": [
"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
{"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
{"encoding": "jsonParsed"}
]
}))
.send().await?
.text().await?;
println!("{}", res);
Ok(())
}Example Response
{
"jsonrpc": "2.0",
"result": {
"context": { "slot": 166974442 },
"value": [
{
"pubkey": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD",
"account": {
"data": { "parsed": { "type": "account", "info": {} }, "program": "spl-token", "space": 165 },
"executable": false,
"lamports": 2039280,
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
}
]
},
"id": 1
}