Enhanced version of getTokenAccountsByOwner with additional features including cursor-based pagination and changedSinceSlot support for efficiently retrieving SPL token accounts owned by a specific wallet address.
getTokenAccountsByOwnerV2 is an enhanced version of the standard getTokenAccountsByOwner method, specifically designed for efficiently querying token portfolios and handling wallets with extensive token holdings. This method introduces cursor-based pagination and incremental update capabilities.
New Features in V2:
Cursor-based pagination: Configure limits from 1 to 10,000 token accounts per request
Incremental updates: Use changedSinceSlot to fetch only recently modified token accounts
Portfolio scalability: Handle wallets with thousands of token accounts efficiently
Backward compatibility: Supports all existing getTokenAccountsByOwner parameters and filters
Optional withContext: Request snapshot metadata (slot, apiVersion) in a standard Solana-style wrapped result
Filter Requirement: You must provide either a mint (specific token) or programId (SPL Token or Token-2022 program) in your query. Querying all token types for an owner without a filter is not supported.
withContext is a boolean on the configuration object (third parameter — alongside encoding, limit, and so on). It only changes the JSON shape of result, not filters, limits, or pagination behavior.
Omitted or false: Matches the familiar shape: the token account list for the page is result.value as an array, with result.paginationKey and result.totalResults on result.
true: The RPC returns the wrapped shape: result.context (snapshot metadata, including slot and usually apiVersion) and result.value as an object with accounts, paginationKey, and totalResults.
Important Pagination Behavior: End of pagination is only indicated when no token accounts are returned. The API may return fewer accounts than your limit due to filtering - always continue pagination until paginationKey is null.
Token-2022 Support: Use TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb as the programId to query Token-2022 accounts with extensions like transfer fees, interest-bearing tokens, and more.
When true, returns result.context (slot, apiVersion) and nests accounts, paginationKey, and totalResults under result.value as an object. When false or omitted, result.value is the token account array for this page, with paginationKey and totalResults on result. Same query semantics as without this flag.
Paginated token accounts when withContext is false or omitted. Matches the familiar shape where the account list is result.value as an array (not nested under accounts).