getTokenAccountsByOwnerV2
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.
Overview
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.
- Cursor-based pagination: Configure limits from 1 to 10,000 token accounts per request
- Incremental updates: Use
changedSinceSlotto fetch only recently modified token accounts - Portfolio scalability: Handle wallets with thousands of token accounts efficiently
- Backward compatibility: Supports all existing
getTokenAccountsByOwnerparameters and filters - Optional
withContext:trueaddsslotandapiVersionunderresult.context; omit orfalseand they are not included
Key Benefits
Large Portfolios
Real-time Tracking
changedSinceSlot for incremental updateswithContext (optional)
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). If you handle both, branch on Array.isArray(result.value).
Pagination Best Practices
Basic Portfolio Query
Incremental Portfolio Updates
Token Program Support
Migration from getTokenAccountsByOwner
Migration is simple - just add pagination parameters to your existing queries:Related Methods
getTokenAccountsByOwner
getProgramAccountsV2
Request Parameters
confirmedfinalizedprocessed
true, returns result.context (snapshot metadata: slot, apiVersion) and nests
accounts and paginationKey under result.value as an object. When false
or omitted, result.value is the token account array for this page, with paginationKey
on result. Same filters and limits apply.base58base64base64+zstdjsonParsed
Authorizations
Body
The JSON-RPC protocol version.
2.0 "2.0"
A unique identifier for the request.
"1"
The name of the RPC method to invoke.
getTokenAccountsByOwnerV2 "getTokenAccountsByOwnerV2"
Parameters for querying paginated token accounts owned by a specific public key.
Solana wallet address (pubkey) of the account owner to query token holdings for, as a base-58 encoded string.
"A1TMhSGzQxMr1TboBKtgixKz1sS6REASMxPo1qsyTSJd"
Response
Successfully retrieved paginated token accounts by owner.
The JSON-RPC protocol version.
2.0 "2.0"
Identifier matching the request.
"1"
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).
- without withContext
- with withContext