Documentation index

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

#TypeRequiredDescription
1stringYesBase-58 encoded public key of the delegate to query
2objectYesFilter object -- must contain either mint or programId
3objectNoConfiguration object

Configuration object fields:

FieldTypeDescription
mintstringFilter by SPL Token mint address (base-58)
programIdstringFilter by SPL Token program ID (base-58)
encodingstringData encoding: base64, base64+zstd, or jsonParsed
commitmentstringCommitment level: processed, confirmed, or finalized
dataSliceobjectLimit returned data: { offset: number, length: number }
minContextSlotnumberMinimum slot at which the request can be evaluated

Response

Returns an RpcResponse with an array of token account objects:

FieldTypeDescription
context.slotu64The slot at which the value was read
value[].pubkeystringToken account address (base-58)
value[].account.dataobjectToken account data in the requested encoding
value[].account.lamportsu64Lamports in the token account
value[].account.ownerstringToken program ID

Code Examples

cURL

Terminal
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

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

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

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

JSON
{
  "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
}