0

I have a local ethereum node and I am trying to filter an event for a contract address between a range of blocks. However it throws the following error:

node:15689) UnhandledPromiseRejectionWarning: Error: Returned error: query returned more than 10000 results
    at Object.ErrorResponse (/mnt/ssd/abi_extraction/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /mnt/ssd/abi_extraction/node_modules/web3-core-requestmanager/src/index.js:170:36
    at XMLHttpRequest.request.onreadystatechange (/mnt/ssd/abi_extraction/node_modules/web3-providers-http/src/index.js:111:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/mnt/ssd/abi_extraction/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/mnt/ssd/abi_extraction/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/mnt/ssd/abi_extraction/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/mnt/ssd/abi_extraction/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:15689) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15689) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This was when my toBlock was 9095563 and fromBlock was 8945008. Even when I reduced the block range by a mere 10 blocks, it was returning the same error. My code is below:

const Web3 = require('web3');
const fetch = require('node-fetch');

let infura_url = "https://mainnet.infura.io/v3/853346f695b740fe8bd7d8f583bcf55f"
let web3 = Web3(Web3.IPCProvider("./../.ethereum/geth.ipc"))

const params = {
    address: "0x0e3a2a1f2146d86a604adc220b4967a898d7fe07",
    topics: ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],
    fromBlock: 8945008,
    toBlock: 9095563  
};

web3.eth.getPastLogs(params).then(response => {
    console.log(response);
});

Is there a way to bypass this so that I can get more than 10000 results:

  1. For 10 block difference issue
  2. For the range mentioned in the code.
  • How exactly is the range [8945008, 9095563] "a mere 10 blocks"??? – goodvibration Jul 7 at 13:47
  • I said that it returns same error for both ranges when the difference is 10 blocks or when the difference is that as shown above – mahamzaidi Jul 7 at 13:48
  • Well, I tried from 8945008 to 8945018, and I did not encounter the problem that you're mentioning. Perhaps you'd care to be a little more specific and state exactly which range of 10 blocks is giving you this error. – goodvibration Jul 7 at 13:52
  • Im trying to execute the same code on two system. One system fetches the logs for a maximum difference of 60 block i.e. when my toBlock is 8945068. But the same code on an another system which also has a local ethereum node doesn't even run for toBlock = 8945018 – mahamzaidi Jul 7 at 13:55
  • That doesn't quite sound like the original problem posted. Do you have a range of 10 blocks for which you get "query returned more than 10000 results" or not? – goodvibration Jul 7 at 13:56
1

You can solve this problem using Divide & Conquer strategy:

async function getPastLogs(web3, address, topics, fromBlock, toBlock) {
    if (fromBlock <= toBlock) {
        try {
            return await web3.eth.getPastLogs({address, topics, fromBlock, toBlock});
        }
        catch (error) {
            const midBlock = (fromBlock + toBlock) >> 1;
            const arr1 = await getPastLogs(web3, address, topics, fromBlock, midBlock);
            const arr2 = await getPastLogs(web3, address, topics, midBlock + 1, toBlock);
            return [...arr1, ...arr2];
        }
    }
    return [];
}
| improve this answer | |
  • Just keep in mind that if web3.eth.getPastLogs throws an error even for a single block (for example, as a result of network disconnection), then it will be stuck in infinite recursion, and the process will ultimately exit due to stack overflow. – goodvibration Jul 7 at 14:14
0

I solved my problem. Apparently the issue was with the IPC provider. I changed it to HttpProvider(path_to_local_node) and now it is working flawlessly on the ethereum node and returning logs as desired. I am posting the updated code:

let web3 = new Web3(new Web3.providers.HttpProvider(nodeURL));

const params = {
    address: "0x0e3a2a1f2146d86a604adc220b4967a898d7fe07",
    topics: ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],
    fromBlock: 8945008,
    toBlock: 8945078
};

web3.eth.getPastLogs(params).then(response => {
    console.log(response);
}).catch(err => {
    console.log(err);
});
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.