Retrieve all compressed accounts owned by a specific address. RPC method guide with use cases, tips and examples.
POST
/
getCompressedAccountsByOwner
Copy
Ask AI
{ "context": "<any>", "value": "<any>"}
ThegetCompressedAccountsByOwner RPC method returns all compressed accounts owned by a specific address, with support for filtering, pagination, and data slicing.
You can test this method via the OpenAPI example or custom examples below.
Common Use Cases
Portfolio Discovery: Find all compressed accounts for a wallet
Account Migration: Identify accounts to migrate from regular to compressed
Balance Aggregation: Calculate total holdings across all accounts
Parameters
owner (PublicKey, required): Base58-encoded public key of the account owner to query compressed accounts for.
options (object, optional): Configuration object for filtering and pagination:
filters (array, optional): Array of filter objects to narrow results by specific criteria
dataSlice (object, optional): Slice of account data to return with offset and length fields
cursor (string, optional): Cursor for pagination from previous response to fetch next page
limit (BN, optional): Maximum number of accounts to return (use bn() helper)
Note: All options parameters are optional. Without filters, returns all compressed accounts for the owner.ResponseThe response contains a paginated list of compressed accounts:
items (array): Array of compressed account objects with merkle context
hash (string): Unique hash identifying the account for merkle proof generation
address (string, optional): Account address if available
lamports (number): Account balance in lamports
owner (string): Public key of the account owner
data (object): Account data information including discriminator and data hash
tree (string): Public key of the merkle tree storing this account
leafIndex (number): Position of account in the merkle tree
seq (number): Sequence number for account ordering
slotCreated (number): Slot when account was created
cursor (string | null): Pagination cursor for next batch, null if no more results
Developer Tips
Pagination Strategy: Use cursor-based pagination for owners with many accounts to avoid timeouts and ensure consistent results
Data Slicing Optimization: Implement data slicing when you only need account metadata to reduce response size and improve performance
Empty Response Handling: Handle cases gracefully where new addresses have no compressed accounts - this is normal behavior
Caching Considerations: Cache results appropriately as compressed account states can change with each transaction
Batch Size: Start with smaller batch sizes (50-100) and adjust based on response times and data needs
Troubleshooting
No accounts found
Owner has no compressed accountsThis is normal for new addresses or those that haven’t used compression:
Copy
Ask AI
const accounts = await rpc.getCompressedAccountsByOwner(owner);if (accounts.items.length === 0) { console.log("No compressed accounts found for this owner"); console.log("Create compressed accounts first using createAccountWithLamports or token operations");}
Request timeout with large responses
Too many accounts returned at onceUse pagination and data slicing to reduce response size: