I am writing a function to sync all transactions on a particular contract from a particular account in my local database to build a dashboard for account owners. I need to fetch all the past transfer events from the blockchain but I am getting the error that the call returned more than 10000 results sync function

syncTransactions(contract_address, owner_address, max_block) {
  const contract = new web3.eth.Contract(abi, contract_address);
  const from_block = max_block - 1000 >= 0 ? max_block - 1000 : 0;
      fromBlock: from_block,
      toBlock: max_block,
    (err, events) => {
      if (err) {
      for (let i = 0; i < events.length; i++) {
        // check if 'to' or 'from' is equal to owner_account, if yes, add it to local database
      syncTransactions(contract_address, owner_address, from_block - 1);

I haven't gotten to the point of filtering transactions using the given owner account. How can I avoid this error? Is there a better way to do this?

P.S. I have tried using both https and web socket URLs provided by Infura but getting the same error.

  • You can try something similar to the suggestion in this answer. Just replace web3.eth.getPastLogs with contract.getPastEvents, and apply all required subsequent fixes (input parameters, etc). – goodvibration Jul 29 at 10:46
  • Iterate over smaller batches of blocks to retrieve smaller batches of events instead of asking for everything in one gulp. – Rob Hitchens Jul 29 at 16:03
  • This is by design.. infura limits log queries to the past 10,000 events – Samuel Dare Aug 4 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.