getTokenAccountsByDelegate - Solana

This method returns all SPL Token accounts whose approved delegate matches the supplied address. Results can be narrowed to a single mint or a single token program.

Parameters

ParameterTypeRequiredDescription
delegatestringYesBase58-encoded Pubkey of the account delegate
filterobjectYesFilter object specifying either a mint or a programId
configobjectNoConfiguration object controlling encoding and commitment

Filter Object

FieldTypeRequiredDescription
mintstringNoRestrict results to token accounts for this mint
programIdstringNoRestrict results to accounts owned by this token program

Config Object

FieldTypeRequiredDescription
encodingstringNoData encoding: base58, base64, base64+zstd, or jsonParsed
commitmentstringNoCommitment level: processed, confirmed, or finalized. Defaults to finalized
dataSliceobjectNoByte range to return, with offset and length fields
minContextSlotnumberNoMinimum slot the request can be evaluated at

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getTokenAccountsByDelegate",
    "params": ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}, {"encoding": "jsonParsed"}],
    "id": "getblock.io"
}'

example.js

javascriptconst { Connection, PublicKey } = require('@solana/web3.js');

const connection = new Connection('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', 'confirmed');

const { value } = await connection.getParsedTokenAccountsByDelegate(
  new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
  { programId: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') }
);

console.log(value);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getTokenAccountsByDelegate',
        'params': ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}, {"encoding": "jsonParsed"}],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    const client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getTokenAccountsByDelegate",
            "params": ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}, {"encoding": "jsonParsed"}],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "context": {
            "apiVersion": "2.3.6",
            "slot": 397234561
        },
        "value": []
    }
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultobjectRPC response object where value is an array of matching token accounts

Value Entry

FieldTypeDescription
pubkeystringBase58 Pubkey of the token account
accountobjectAccount object with lamports, owner, data, executable, rentEpoch, and space

Use Cases

  • Delegation Audits: List every token account a protocol has been approved to move
  • Escrow Tracking: Verify delegate approvals before executing a transfer
  • Revocation Flows: Surface active delegations so a user can revoke them
  • Security Review: Detect unexpected delegate authority on user token accounts

Error Handling

Error CodeMessageDescription
-32602Invalid paramsFilter omits both mint and programId, or supplies both
-32603Internal errorNode failed to scan token accounts for the delegate
-32005Node is unhealthyThe node has fallen behind the cluster tip