getTokenAccountsByOwner
Learn getTokenAccountsByOwner use cases, code examples, request parameters, response structure, and tips.
The getTokenAccountsByOwner RPC method in CoinVera is used to retrieve all SPL token accounts owned by a specific wallet address (public key). This is a core method for wallets, explorers, and applications that need to display token balances or interact with a userβs token accounts.
You must filter the request using either a specific token mint or a programId (such as the SPL Token Program or Token-2022 Program).
β Common Use Cases
Displaying User Portfolio Retrieve all token accounts owned by a wallet to display the userβs full token holdings.
Token Transfer Logic Identify the token account associated with a specific mint before sending or receiving tokens.
Ownership Verification Check whether a wallet owns a token account for a particular token.
Indexing Known Holders Though less efficient than global indexing, this can be used to find token accounts across known users.
π§Ύ Request Parameters
[
ownerPubkey: string, // Required β The public key of the wallet.
filter: {
mint?: string, // Optional β Specific token mint to filter by.
programId?: string // Optional β Token program ID to filter accounts (e.g. SPL or Token-2022).
},
options?: {
commitment?: string, // Optional β Commitment level (processed, confirmed, finalized).
encoding?: string, // Optional β Data encoding ("jsonParsed" recommended).
dataSlice?: { offset: number, length: number }, // Optional β Only used for binary encodings.
minContextSlot?: number // Optional β Minimum context slot.
}
]π‘ Filter Requirement:
You must provide either a mint or a programId. Without one, the query is invalid.
Common program IDs:
SPL Token Program:
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DAToken-2022 Program:
TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
π¦ Response Structure
π§ͺ Examples
Get All Token Accounts for a Wallet (SPL Token Program)
Filter by Specific Mint
Code Examples
Example Response
π‘ Developer Tips
Mandatory Filter Either
mintorprogramIdmust be providedβyou cannot retrieve all token accounts unfiltered.Associated Token Accounts (ATAs) Results include standard ATAs as well as manually created or legacy token accounts.
Use
jsonParsedHighly recommended for easier access to account fields like balance, owner, and mint.Performance Consideration If filtering only by
programId, results may be large. Consider batching wallet lookups if working with multiple addresses.Token Extensions For Token-2022 tokens (e.g., with transfer fees, interest-bearing extensions), make sure you use the correct program ID:
TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb.
The getTokenAccountsByOwner method is essential for any wallet or token-aware Solana app powered by CoinVera. It offers a clear view into a userβs on-chain token holdings, including advanced support for both standard and extended SPL tokens.
Last updated