Batch Processing Guide
Best practices for processing large volumes of data through the CryptaChain API.
Rate limit-aware batching
On the Free tier (10 req/min), batch your requests with delays:
typescript
const DELAY_MS = 6500; // ~9.2 req/min (safe under 10 req/min limit)
async function batchProcess(addresses: string[], chain: string) {
const results = [];
for (const addr of addresses) {
const res = await fetch(
`https://api.cryptachain.com/v1/wallets/${addr}/balances?chain=${chain}`,
{ headers: { 'X-API-Key': key } }
);
results.push(await res.json());
// Respect rate limits
if (results.length < addresses.length) {
await new Promise(r => setTimeout(r, DELAY_MS));
}
}
return results;
}Adaptive rate limiting
Monitor the X-RateLimit-Remaining header to adapt your request rate:
typescript
async function adaptiveRequest(url: string) {
const res = await fetch(url, { headers: { 'X-API-Key': key } });
const remaining = parseInt(res.headers.get('X-RateLimit-Remaining') || '10');
const reset = parseInt(res.headers.get('X-RateLimit-Reset') || '0');
const now = Math.floor(Date.now() / 1000);
const windowRemaining = Math.max(1, reset - now);
// If running low, spread remaining budget across the window
if (remaining < 3) {
const delay = (windowRemaining / remaining) * 1000;
await new Promise(r => setTimeout(r, delay));
}
return res;
}Pagination best practices
For endpoints with cursor-based pagination:
- Always use cursor pagination — offset-based pagination becomes slow for large datasets
- Process pages sequentially — each page depends on the previous cursor
- Use maximum page size —
limit=1000uses 1 API call vs 10 calls withlimit=100 - Cache results — if re-processing the same data, cache locally
typescript
async function fetchAllTransfers(address: string, chain: string) {
const all = [];
let cursor: string | undefined;
do {
const params = new URLSearchParams({ chain, limit: '1000' });
if (cursor) params.set('cursor', cursor);
const res = await adaptiveRequest(
`${BASE}/v1/wallets/${address}/transfers?${params}`
);
const data = await res.json();
all.push(...data.transfers);
cursor = data.hasMore ? data.cursor : undefined;
} while (cursor);
return all;
}Recommendations by tier
| Tier | Concurrent requests | Strategy |
|---|---|---|
| Free | 1 (sequential) | 6.5s delay between requests |
| Standard | 2-3 | Adaptive rate limiting |
| Professional | 10-20 | Parallel with rate header monitoring |
| Enterprise | Custom | Contact us for bulk data feeds |