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

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: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA

  • Token-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 mint or programId must 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 jsonParsed Highly 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