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: true adds slot and apiVersion under result.context; omit or false and they are not included
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.
Boolean on the config object (params[2]). Only the shape of result changes, not filters, limits, or pagination. Omitted or false: result.value is the token account array. true: result.context plus result.value as an object (accounts, paginationKey, totalResults). If you handle both, branch on Array.isArray(result.value).
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.
Optional. When true, result.value is an object with accounts (and result.context has slot/apiVersion). When omitted or false, result.value is the account array.
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).