Skip to content

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:

  1. Always use cursor pagination — offset-based pagination becomes slow for large datasets
  2. Process pages sequentially — each page depends on the previous cursor
  3. Use maximum page sizelimit=1000 uses 1 API call vs 10 calls with limit=100
  4. 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

TierConcurrent requestsStrategy
Free1 (sequential)6.5s delay between requests
Standard2-3Adaptive rate limiting
Professional10-20Parallel with rate header monitoring
EnterpriseCustomContact us for bulk data feeds

CryptaChain API — built by CryptaCount Luxembourg S.a r.l.