Indexing & Retrieving Data
Learn how to index Solana blockchain data and retrieve it efficiently using Wind Network
This guide demonstrates how to index Solana blockchain data and retrieve it efficiently using the wIndexer network. Our decentralized indexing solution makes it simple to access blockchain data without relying on centralized RPC providers.
Prerequisites
- ✓Basic knowledge of Solana blockchain
- ✓Node.js environment (for SDK examples)
- ✓Access to wIndexer network at test-may-us-01.windnetwork.ai
Using the REST API
Checking the Network Status
Before indexing or retrieving data, ensure the wIndexer network is operational:
curl http://test-may-us-01.windnetwork.ai/api/health
Expected response:
{
"status": "ok",
"uptime": 12345,
"version": "0.1.0"
}
Indexing Transactions
When you submit transactions to the Solana network, Wind Network automatically indexes them. For example, after submitting a transaction, you can track its indexing status:
# Replace with your transaction signature
export SIGNATURE="your_transaction_signature"
# Check if the transaction has been indexed
curl http://test-may-us-01.windnetwork.ai/indexer1/api/transaction/$SIGNATURE
Retrieving Indexed Data
Once data is indexed, you can retrieve it through various endpoints:
Recent Blocks
curl http://test-may-us-01.windnetwork.ai/indexer1/api/blocks/recent
Account Information
# Replace with the account public key
export ACCOUNT="account_public_key"
curl http://test-may-us-01.windnetwork.ai/indexer1/api/account/$ACCOUNT
Program Accounts
# Replace with program ID
export PROGRAM_ID="program_id"
curl http://test-may-us-01.windnetwork.ai/indexer1/api/program/$PROGRAM_ID/accounts
Advanced Indexing Patterns
Real-time Indexing
Use WebSocket connections to receive real-time updates as data is indexed:
const ws = new WebSocket('ws://test-may-us-01.windnetwork.ai/ws/accounts');
ws.on('message', (data) => {
const update = JSON.parse(data);
console.log('Account updated:', update);
});
// Subscribe to specific accounts
ws.send(JSON.stringify({
type: 'subscribe',
accounts: ['account1...', 'account2...']
}));
Batch Queries
Optimize performance by batching multiple queries:
import { WindClient } from '@windnetwork/sdk';
const client = new WindClient('http://test-may-us-01.windnetwork.ai:3000/api');
// Batch account queries
const accounts = [
'account1...',
'account2...',
'account3...'
];
const results = await client.getAccountsBatch(accounts);
Historical Data Queries
Query historical data using slot ranges:
// Get account history between specific slots
const history = await client.getAccountHistory('account_pubkey', {
startSlot: 150000000,
endSlot: 151000000
});
// Get transactions in a time range
const transactions = await client.getTransactions({
startTime: '2024-01-01T00:00:00Z',
endTime: '2024-01-02T00:00:00Z',
program: 'program_id'
});
Best Practices
Use Appropriate Storage Backend
Choose RocksDB for real-time queries, Parquet for analytics, and PostgreSQL for complex queries.
Implement Caching
Cache frequently accessed data to reduce API calls and improve application performance.
Handle Rate Limits
Implement exponential backoff and respect rate limit headers to ensure reliable access.
Use WebSocket for Real-time Data
Instead of polling, use WebSocket connections for real-time updates to reduce latency and server load.
Example: Token Balance Tracker
Here's a complete example of a token balance tracker using Wind Network:
import { WindClient } from '@windnetwork/sdk';
import { Connection, PublicKey } from '@solana/web3.js';
class TokenBalanceTracker {
constructor() {
this.client = new WindClient('http://test-may-us-01.windnetwork.ai:3000/api');
this.subscriptions = new Map();
}
async trackWallet(walletAddress) {
// Get initial token balances
const tokens = await this.client.getAccountTokens(walletAddress);
console.log('Initial tokens:', tokens);
// Subscribe to real-time updates
const ws = this.client.subscribeToAccount(walletAddress, (update) => {
console.log('Balance update:', update);
this.handleBalanceUpdate(walletAddress, update);
});
this.subscriptions.set(walletAddress, ws);
}
handleBalanceUpdate(wallet, update) {
// Process balance updates
if (update.type === 'token_balance_change') {
console.log(`Token ${update.mint} balance changed to ${update.amount}`);
// Update UI or trigger notifications
}
}
async getHistoricalBalances(wallet, days = 7) {
const endTime = new Date();
const startTime = new Date(endTime - days * 24 * 60 * 60 * 1000);
return await this.client.getAccountHistory(wallet, {
startTime: startTime.toISOString(),
endTime: endTime.toISOString(),
dataType: 'token_balances'
});
}
stopTracking(wallet) {
const ws = this.subscriptions.get(wallet);
if (ws) {
ws.close();
this.subscriptions.delete(wallet);
}
}
}
// Usage
const tracker = new TokenBalanceTracker();
await tracker.trackWallet('YourWalletAddress...');
Troubleshooting
Data Not Appearing
If indexed data doesn't appear immediately, check:
- • Network status using the health endpoint
- • Transaction confirmation on Solana explorer
- • Allow 1-2 seconds for indexing to complete
Rate Limit Errors
If you encounter rate limit errors:
- • Implement exponential backoff
- • Cache responses when possible
- • Use batch queries instead of individual requests
WebSocket Connection Issues
For WebSocket connection problems:
- • Check firewall settings
- • Implement reconnection logic
- • Monitor connection health with ping/pong
Ready to Build?
Start building with Wind Network's powerful indexing capabilities