For the complete documentation index, see llms.txt. This page is also available as Markdown.

getTokenAccountsByDelegate - Solana

Example code for the getTokenAccountsByDelegate JSON-RPC method. Complete guide on how to use the getTokenAccountsByDelegate JSON-RPC method in the GetBlock Web3 documentation.

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

Parameter
Type
Required
Description

delegate

string

Yes

Base58-encoded Pubkey of the account delegate

filter

object

Yes

Filter object specifying either a mint or a programId

config

object

No

Configuration object controlling encoding and commitment

Filter Object

Field
Type
Required
Description

mint

string

No

Restrict results to token accounts for this mint

programId

string

No

Restrict results to accounts owned by this token program

Config Object

Field
Type
Required
Description

encoding

string

No

Data encoding: base58, base64, base64+zstd, or jsonParsed

commitment

string

No

Commitment level: processed, confirmed, or finalized. Defaults to finalized

dataSlice

object

No

Byte range to return, with offset and length fields

minContextSlot

number

No

Minimum slot the request can be evaluated at

Request

curl --location --request POST 'https://go.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
const { Connection, PublicKey } = require('@solana/web3.js');

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

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

console.log(value);
example.py
import requests

response = requests.post(
    'https://go.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'])

Response

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

object

RPC response object where value is an array of matching token accounts

Value Entry

Field
Type
Description

pubkey

string

Base58 Pubkey of the token account

account

object

Account 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 Code
Message
Description

-32602

Invalid params

Filter omits both mint and programId, or supplies both

-32603

Internal error

Node failed to scan token accounts for the delegate

-32005

Node is unhealthy

The node has fallen behind the cluster tip

Was this helpful?