const startBlock = deploymentBlock; // First block to scan; when resuming, use the saved cursor + 1.
const step = 10000; // Shrink the window if a request hits the 10000-log cap.
const latest = await provider.getBlockNumber();
for (let from = startBlock; from <= latest; from += step) {
const to = Math.min(from + step - 1, latest);
const page = await provider.getLogs({
address: contractAddress,
topics: [ethers.id("Transfer(address,address,uint256)")],
fromBlock: from,
toBlock: to,
});
// Process `page`, then persist `to` as the cursor.
}