getTokenAccountsByOwner

The getTokenAccountsByOwner method returns all SPL Token accounts owned by a specified address, optionally filtered by token mint or token program. This is one of the most important methods for wallet applications, as it enables discovering all token holdings for a user in a single query.

In Solana's account model, each token type a user holds requires a separate account. A user with 10 different tokens has 10 different token accounts, all owned by their wallet address. This method discovers all these accounts, enabling wallets to display complete token portfolios without prior knowledge of which tokens the user holds. It's essential for providing the "what tokens do I have?" functionality that users expect from modern wallets.

This method is crucial for wallet applications building portfolio views, DEXes discovering available trading balances, NFT platforms finding all NFTs owned by a user, and any application that needs a comprehensive view of a user's token holdings. The method supports filtering by specific token mints for targeted queries or returning all token accounts for complete portfolio enumeration.


Parameters

parameter
type
description
ownerPubkey
string
Base-58 encoded public key of the account owner
filter
object
Filter object - must specify either 'mint' or 'programId'
filter.mint
string
Base-58 encoded public key of the token mint (filters to accounts of this token type)
filter.programId
string
Base-58 encoded public key of the token program (e.g., Token or Token-2022 program)
config
object
Optional configuration object
config.commitment
string
Level of commitment: 'processed', 'confirmed', or 'finalized' (default: 'finalized')
config.encoding
string
Encoding for account data: 'base58', 'base64', 'base64+zstd', or 'jsonParsed' (default: 'base58')
config.dataSlice
object
Optional. Request a slice of account data
config.minContextSlot
number
Optional. Minimum slot that the request can be evaluated at
Return Object
field
type
description
context
object
RPC response context with slot information
context.slot
number
The slot at which this data was retrieved
value
array
Array of token account information objects
value[].pubkey
string
The token account public key as base-58 encoded string
value[].account
object
Account information object
value[].account.lamports
number
Number of lamports assigned to this account
value[].account.owner
string
Base-58 encoded public key of the token program
value[].account.data
object
Token account data (parsed if encoding is 'jsonParsed')
value[].account.executable
boolean
Boolean indicating if the account contains a program (always false for token accounts)
value[].account.rentEpoch
number
The epoch at which this account will next owe rent
Request Example
Request
Response Example
Response

Tip: Use programId: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA to get all SPL tokens, or specify a mint to find accounts for a specific token. Always use jsonParsed encoding for easy access to parsed token data. For Token-2022 program, use programId TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb.


Share on
Share on FacebookShare on XShare on LinkedIn
Did you find this page useful?