PD

PayDirect Blog

Chunking the Chain: Say Goodbye to RPC Headaches with PayDirect!

PD

PayDirect Team

Jun 1, 2026·3 min read

Chunking the Chain: Say Goodbye to RPC Headaches with PayDirect!

Hey there, blockchain enthusiasts and code wranglers! Gather around; we've got some slick new improvements rolling out of the PayDirect dev kitchen, and if you're the kind that lives and breathes blockchain logs, you're gonna love this. Let's dive into the latest change that might just make your life a whole lot easier: chunking monitor log scans to keep those pesky RPC limits at bay.

Why We Did It

Okay, picture this: you're a serious developer working on a cutting-edge crypto settlement platform with Ethereum L2, specifically Base. You're dealing with a ton of transaction data, and suddenly you hit a wall — the dreaded RPC limits. Your smooth development ride turns into a bumpy one, all thanks to overloading your log requests. Bummer, right?

Well, fear no more! PayDirect’s latest update introduces a more graceful way of handling blockchain log requests. We’ve introduced a nifty solution to chunk your log scans, keeping them within the limits and your development cycle smooth. Here’s how we did it.

The Anatomy of the Update

In the heart of our blockchain-monitor.ts, a new hero emerges: getLogsChunked. This function is your new best friend, taking your log scanning tasks and breaking them down into bite-sized chunks. Here’s a taste of the code magic:

const MAX_RPC_LOG_RANGE_BLOCKS = 1000n;

// Function to handle chunked log retrieval
async function getLogsChunked(
  client: ReturnType<typeof getClient>,
  params: {
    address: `0x${string}`;
    event: typeof TRANSFER_EVENT;
    args: { to: `0x${string}` };
    fromBlock: bigint;
    toBlock: bigint;
  }
) {
  if (params.fromBlock > params.toBlock) return [];

  const logs: Awaited<ReturnType<ReturnType<typeof getClient>["getLogs"]>> = [];
  let cursor = params.fromBlock;

  while (cursor <= params.toBlock) {
    const chunkTo =
      cursor + (MAX_RPC_LOG_RANGE_BLOCKS - 1n) > params.toBlock
        ? params.toBlock
        : cursor + (MAX_RPC_LOG_RANGE_BLOCKS - 1n);

    const chunkLogs = await client.getLogs({
      address: params.address,
      event: params.event,
      args: params.args,
      fromBlock: cursor,
      toBlock: chunkTo,
    });
    logs.push(...chunkLogs);

    cursor = chunkTo + 1n;
  }

  return logs;
}

How It Works

Instead of bombarding your RPC with a massive range of blocks, getLogsChunked thoughtfully breaks down your requests into manageable chunks specified by MAX_RPC_LOG_RANGE_BLOCKS. It's like moving from a firehose approach to a steady stream — much more manageable and oh-so-satisfying.

Each chunk is processed in a loop, ensuring that no block is left unchecked while keeping within the safe limits of what your RPC can handle. It's a game-changer, really.

Why It Matters

For developers, hitting the RPC limits can be as annoying as trying to debug a missing semicolon at 3 a.m. This improvement doesn’t just make your logging more efficient; it preserves your sanity. The enhancement also ensures that your application remains performant and responsive even as it scales, handling larger volumes of transactions smoothly.

File Paths and Functions Galore

This update is nestled within lib/blockchain-monitor.ts, and the main function chef here is getLogsChunked. Our existing main monitoring loop isn't left behind either. It's been retooled to integrate this new function without breaking a sweat, ensuring all ERC-20 tokens like USDC and ADAO are checked more efficiently.

const logs = await getLogsChunked(client, {
  address: token.address as `0x${string}`,
  event: TRANSFER_EVENT,
  args: { to: walletAddress },
  fromBlock: tokenFromBlock,
  toBlock: currentBlock,
});

Final Words: Code Happy, Chain On

With this update, PayDirect is keeping things smooth, sleek, and speedy for all you AI agents and developers tackling the world of crypto settlements. We’re excited for you to try it out — head over to your favorite environment and start experiencing the difference.

Check out the latest changes in our GitHub repo, and don't forget to keep an eye on our docs for any updates. Got feedback or just wanna say hi? Drop us a line; we're always stoked to hear from our fellow blockchain geeks.

Here's to chunking with style and efficiency — catch you on the chain!

Happy coding, and may your logs forever be chunked! 🚀

Tip the Author

Powered by PayDirect on Base

Enjoyed this post? Send a tip using crypto. We eat our own dog food.

USDC

More from PayDirect

Powered by ContentAgent