Learn getTokenAccountsByOwner use cases, code examples, request parameters, response structure, and tips.
getTokenAccountsByOwner
RPC method is used to retrieve all SPL Token accounts owned by a specific public key. This is a fundamental method for wallets and applications that need to display a user’s token holdings or interact with their various token accounts.
You must filter the query by either a specific token mint
or a programId
(e.g., the SPL Token Program or Token-2022 Program).
ownerPubkey
(string, required): The base-58 encoded public key of the account owner whose token accounts you want to retrieve.
filter
(object, required): A JSON object that must specify either mint
or programId
:
mint
(string): The base-58 encoded public key of a specific token mint. If provided, only token accounts for this mint owned by ownerPubkey
will be returned.programId
(string): The base-58 encoded public key of the Token Program that governs the accounts. Common values are:
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
options
(object, optional): An optional configuration object that can include:
commitment
(string, optional): Specifies the commitment level.encoding
(string, optional): The encoding for account data. "jsonParsed"
is highly recommended. Other options: "base64"
, "base64+zstd"
. Defaults to "base64"
.dataSlice
(object, optional): To retrieve a specific slice of the account data (offset
: usize, length
: usize). Only for base58
, base64
, or base64+zstd
encodings.minContextSlot
(u64, optional): The minimum slot for the query.result.value
field in the JSON-RPC response is an array of objects. Each object corresponds to an SPL Token account owned by ownerPubkey
and matching the filter
.
Each object in the value
array contains:
pubkey
(string): The base-58 encoded public key of the token account itself.account
(object): Detailed information about the token account:
lamports
(u64): Lamport balance for rent exemption.owner
(string): The owning program (e.g., the Token Program public key).data
: Account data. If "jsonParsed"
encoding is used, this contains:
program
(string): e.g., "spl-token"
.parsed
: An object with structured information:
info
: Details such as:
mint
(string): The mint address of the token.owner
(string): The owner of the token account (this should match ownerPubkey
from the request).tokenAmount
(object): The balance of tokens (amount
, decimals
, uiAmount
, uiAmountString
).state
(string): State of the token account (e.g., "initialized"
).isNative
(boolean): If the account holds wrapped SOL.delegate
(string, optional): The delegate address if one is set.delegatedAmount
(object, optional): The delegated amount if a delegate is set.type
(string): e.g., "account"
.executable
(boolean): Whether the account is executable.rentEpoch
(u64): Next epoch rent is due.space
(u64, if not jsonParsed
): Length of raw account data in bytes.jsonParsed
encoding, filtered by programId
):
mint
or a programId
in the filter. It’s not possible to query all token accounts for an owner across all token types without one of these primary filters."jsonParsed"
for the encoding
option is highly recommended. It decodes the binary account data into a more usable JSON structure.programId
), the response can be large. Consider pagination if your RPC provider or library supports it, or if you anticipate very large result sets, though this method itself doesn’t directly support pagination in its standard parameters.programId
: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
.getTokenAccountsByOwner
RPC method, enabling you to efficiently retrieve token account information for any Solana address.