Overview
getProgramAccountsV2 is an enhanced version of the standard getProgramAccounts method, designed for applications that need to efficiently query large sets of accounts owned by specific Solana programs. This method introduces cursor-based pagination and incremental update capabilities.
New Features in V2:
- Cursor-based pagination: Configure limits from 1 to 10,000 accounts per request
- Incremental updates: Use
changedSinceSlotto fetch only recently modified accounts - Better performance: Prevents timeouts and reduces memory usage for large datasets
- Backward compatibility: Supports all existing
getProgramAccountsparameters
Key Benefits
Scalable Queries
Handle programs with millions of accounts by paginating through results efficiently
Real-time Sync
Use
changedSinceSlot for incremental updates and real-time data synchronizationPrevent Timeouts
Large queries that previously timed out now work reliably with pagination
Memory Efficient
Process data in chunks instead of loading everything into memory at once
Pagination Best Practices
Basic Pagination Pattern
Incremental Updates
Performance Tips
- Start with smaller limits (1000) and increase based on your network performance
- Use appropriate encoding:
jsonParsedfor convenience,base64for performance - Apply filters to reduce the dataset size before pagination
- Store
paginationKeyto resume queries if interrupted - Monitor response times and adjust limits accordingly
Migration from getProgramAccounts
Migrating from the original method is straightforward - simply replace the method name and add pagination parameters:Related Methods
getProgramAccounts
Original method without pagination
getTokenAccountsByOwnerV2
V2 method for token account queries
Authorizations
Body
application/json