getCompressedTokenAccountsByOwner RPC method retrieves all compressed token accounts owned by a specific public key. The method supports mint filtering to query specific tokens, cursor-based pagination for handling large result sets, and returns parsed token data with merkle context for verification.
You can test this method via the OpenAPI example or custom examples below.
Common Use Cases
- Token Portfolio Display: Show all compressed tokens owned by a wallet address
- Balance Aggregation: Calculate total token holdings across multiple compressed accounts
- Token Transfer Setup: Find available token accounts to use as transfer sources
- Wallet Integration: Support compressed token discovery in wallet interfaces
- DeFi Protocol Integration: Query user token holdings for lending, trading, or staking
owner(PublicKey, required): Base58-encoded public key of the account owner to query token accounts for.options(object, optional): Configuration object containing filtering and pagination parameters:mint(PublicKey, optional): Base58-encoded mint address to filter results by specific tokencursor(string, optional): Pagination cursor from previous response for fetching next pagelimit(BN, optional): Maximum number of accounts to return (usebn()helper function)
items(array): Array of compressed token account objectscompressedAccount(object): Compressed account data and merkle proof contextaddress(string): Compressed account address (if available)owner(string): Account owner public keylamports(number): Account lamportsdata(object): Account data informationhash(string): Account hash for merkle proof verification
parsed(object): Parsed token-specific informationmint(PublicKey): Token mint addressowner(PublicKey): Token account owneramount(BN): Token amount as BN object - use .toString() for exact valuedelegate(PublicKey | null): Delegate address if set, null otherwisestate(number): Account state (0=initialized, 1=frozen, etc.)tlv(Buffer | null): Type-Length-Value extension data if present
cursor(string | null): Pagination cursor for next batch, null if no more results
- BN Object Handling: The
amountfield is a BN object - use.toString()for exact values or.toNumber()for small amounts - State Values: The
statefield is a numeric enum (0=initialized, 1=frozen, etc.) not a string - Parameter Types: Use
bn()helper function for thelimitparameter, not raw numbers - Pagination: Use cursor-based pagination for large token portfolios to avoid timeouts
- Performance: Filter by mint address when querying specific tokens to reduce response size
- Empty Responses: Handle cases where owners have no compressed token accounts gracefully
Dependencies & Setup
Dependencies & Setup
- cURL
- TypeScript
- Rust
TypeScript
TypeScript
TypeScript
Body
application/json
An ID to identify the request.
Available options:
test-account The version of the JSON-RPC protocol.
Available options:
2.0 The name of the method to invoke.
Available options:
getCompressedTokenAccountsByOwner