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
1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "method": "getTokenAccountsByDelegate",
5 "params": [
6 "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
7 { "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
8 { "encoding": "jsonParsed" }
9 ]
10}'TypeScript
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: { "Content-Type": "application/json" },
4 body: JSON.stringify({
5 jsonrpc: "2.0",
6 id: 1,
7 method: "getTokenAccountsByDelegate",
8 params: [
9 "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
10 { programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
11 { encoding: "jsonParsed" }
12 ]
13 }),
14});
15const { result } = await response.json();
16console.log("Delegated accounts:", result.value.length);Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getTokenAccountsByDelegate",
7 "params": [
8 "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
9 {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
10 {"encoding": "jsonParsed"}
11 ]
12})
13result = response.json()["result"]
14print(f"Delegated accounts: {len(result['value'])}")Rust
1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = Client::new();
7 let res = client.post("http://[IP_ADDRESS]:[PORT]")
8 .json(&json!({
9 "jsonrpc": "2.0",
10 "id": 1,
11 "method": "getTokenAccountsByDelegate",
12 "params": [
13 "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",
14 {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},
15 {"encoding": "jsonParsed"}
16 ]
17 }))
18 .send().await?
19 .text().await?;
20 println!("{}", res);
21 Ok(())
22}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "context": { "slot": 166974442 },
5 "value": [
6 {
7 "pubkey": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD",
8 "account": {
9 "data": { "parsed": { "type": "account", "info": {} }, "program": "spl-token", "space": 165 },
10 "executable": false,
11 "lamports": 2039280,
12 "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13 }
14 }
15 ]
16 },
17 "id": 1
18}