OpenInfra.sh is now live - Solana infrastructure, included with every server. LEARN MORE HERE >

OpenInfra.shopeninfra.sh

getTokenAccountsByDelegate

Returns SPL Token accounts whose approved delegate matches the supplied address.

Request

JSON-RPC

{  "jsonrpc": "2.0",  "id": 1,  "method": "getTokenAccountsByDelegate",  "params": [    "9mMBg1qaUaQdht6Q7r5T5VirRzJbNAyquKTq96FyR4UC",    {      "mint": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"    },    {      "commitment": "finalized",      "encoding": "jsonParsed"    }  ]}

Kit (TypeScript)

import { address, createSolanaRpc } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let delegate = address("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");let tokenProgram = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); let tokenAccByDelegate = await rpc  .getTokenAccountsByDelegate(    delegate,    { programId: tokenProgram },    {      commitment: "finalized",      encoding: "jsonParsed"    }  )  .send(); console.log(tokenAccByDelegate);

Rust

use anyhow::Result;use solana_client::{nonblocking::rpc_client::RpcClient, rpc_request::TokenAccountsFilter};use solana_commitment_config::CommitmentConfig;use solana_sdk::pubkey; #[tokio::main]async fn main() -> Result<()> {    let client = RpcClient::new_with_commitment(        String::from("https://rpc.openinfra.sh"),        CommitmentConfig::confirmed(),    );     let delegate = pubkey!("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF");    let token_program = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");     let token_acc_by_del = client        .get_token_accounts_by_delegate_with_commitment(            &delegate,            TokenAccountsFilter::ProgramId(token_program),            CommitmentConfig::finalized(),        )        .await?;     println!("{:#?}", token_acc_by_del);     Ok(())}

Parameters

ParameterTypeRequiredDescription
pubkeystringRequiredPubkey of the account delegate to query, as a base-58 encoded string.
filterobjectRequiredA JSON object with exactly one of: mint (base-58 pubkey of the specific token mint) or programId (base-58 pubkey of the Token program that owns the accounts).
configobjectOptionalConfiguration object. See config fields below.

config fields

FieldTypeDefaultDescription
commitmentstringfinalizedCommitment level: processed, confirmed, or finalized.
encodingstringbinaryAccount-data encoding. One of base58, base64, base64+zstd, binary (deprecated), or jsonParsed.
minContextSlotnumberMinimum slot at which the request may be evaluated.
dataSliceobjectByte slice of account data to return: offset (usize) and length (usize). Only valid with binary encodings.

Commitment levels

ValueDescription
processedData from the highest slot this node has processed on the fork it currently considers best. Newest, but can change if the cluster switches forks.
confirmedData from the highest slot that at least two-thirds of active stake has directly voted to confirm. More stable than processed, weaker than finalized.
finalizedData from the highest slot the cluster recognizes as finalized — maximum vote lockout and confirmed by at least two-thirds of active stake.

Encoding formats

EncodingData formatNotes
base64[data, "base64"]Recommended.
base58[data, "base58"]Slow. Account data must be 128 bytes or fewer.
base64+zstd[data, "base64+zstd"]Zstandard-compressed.
jsonParsed{program, parsed, space}Falls back to base64 if no parser is found.
binarystringDeprecated. Same as base58 but returns data as a plain string. Use base64 instead.

Response

{  "jsonrpc": "2.0",  "result": {    "context": { "apiVersion": "3.1.8", "slot": 1114 },    "value": [      {        "pubkey": "28YTZEwqtMHWrhWcvv34se7pjS7wctgqzCPB3gReCFKp",        "account": {          "data": {            "program": "spl-token",            "parsed": {              "info": {                "tokenAmount": {                  "amount": "1",                  "decimals": 1,                  "uiAmount": 0.1,                  "uiAmountString": "0.1"                },                "delegate": "4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T",                "delegatedAmount": {                  "amount": "1",                  "decimals": 1,                  "uiAmount": 0.1,                  "uiAmountString": "0.1"                },                "state": "initialized",                "isNative": false,                "mint": "3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E",                "owner": "CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"              },              "type": "account"            },            "space": 165          },          "executable": false,          "lamports": 1726080,          "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",          "rentEpoch": 4,          "space": 165        }      }    ]  },  "id": 1}

RpcResponse fields

FieldTypeDescription
contextobjectSlot and API version the node used to answer the request.
valuearrayArray of keyed-account objects matching the delegate.

context fields

FieldTypeDescription
slotu64Slot at which the node evaluated the request.
apiVersionstringRPC API version reported by the node. May be omitted by older nodes.

value[] item fields

FieldTypeDescription
pubkeystringAccount pubkey, as a base-58 encoded string.
accountobjectAccount data object using the shared Account Data structure.

account fields

FieldTypeDescription
datastring | [string, encoding] | objectToken account data. When encoding is jsonParsed, returned as { program, parsed, space }; falls back to [data, "base64"] if no parser is available.
executableboolWhether the account contains a program and is therefore read-only.
lamportsu64Lamports assigned to the account.
ownerstringProgram owner pubkey, as a base-58 encoded string.
rentEpochu64Next epoch at which the account owes rent.
spaceu64 | nullAccount data size in bytes.

account.data (jsonParsed) fields

FieldTypeDescription
programstringName of the parser that produced the decoded data (e.g. spl-token or spl-token-2022).
parsedobjectParsed SPL Token account payload.
spaceu64Account data size in bytes.

parsed fields

FieldTypeDescription
typestringAlways account for this method.
infoobjectParsed SPL Token account fields.

parsed.info fields

FieldTypeDescription
mintstringToken mint pubkey, as a base-58 encoded string.
ownerstringToken-account owner pubkey, as a base-58 encoded string.
tokenAmountobjectToken amount with raw and decimal-scaled representations.
delegatestring | nullDelegate pubkey, when a delegate is set.
statestringToken-account state: uninitialized, initialized, or frozen.
isNativeboolWhether this account wraps the native SOL mint.
rentExemptReserveobject | nullRent-exempt reserve for wrapped SOL accounts. Uses the same schema as tokenAmount.
delegatedAmountobject | nullAmount delegated to the delegate, when present. Uses the same schema as tokenAmount.
closeAuthoritystring | nullClose-authority pubkey, when present.
extensionsarrayParsed SPL Token 2022 extension entries. Each element has an extension discriminator and an extension-specific state payload.

tokenAmount fields

FieldTypeDescription
uiAmountnumber | nullDecimal-scaled amount as a floating-point number. Deprecated in favor of uiAmountString.
decimalsu8Number of decimal places configured on the mint.
amountstringRaw token amount, as a base-10 integer string.
uiAmountStringstringDecimal-scaled amount as a string.