0

I am using web3js to query a remote geth node (Geth/v1.8.14-unstable-35fcd2f4/linux-amd64/go1.10.3) for a particular event Ping emitted by a smart contract.

myinstance = new web3.eth.Contract(myABI, myAddress)

myinstance.getPastEvents('Ping', {
    fromBlock: startBlockNumber,
    toBlock: endBlockNumber
}, async function(err, events) {
    if(err) {
        console.log(err)
    } else {
        for (const e of events) {
            console.log(Txhash ' + e.transactionHash)
        }
    }
});

This gives the following error if startBlockNumber is set to 10000, which appears to contain a large json string with the desired response, which appears to be truncated near the end:

Error: Invalid JSON RPC response: "{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[{\"address\":\"0xa70f993d5dd72dd8567b3da7ed1a945a39ab44b1\",\"topics\":[\"0xee9ff4d977958c645eb6c38f9c80e3e0fea7031421dbba4c206f972150ad43e8\",\"0x0000000000000000000000008a5e9fd75efbca27b153875d6f5caf6a62b95615\"],\"data\":\"0x0000000000000000000000000000000000000000000000000000000000000064\",\"blockNumber\":\"0x186a2\",\"transactionHash\":\"0x94bddc09fb0fb497d2091a28689dfc41eb1a5915737133404555eab2107efca9\",\"transactionIndex\":\"0x0\",\"blockHash\":\"0x6c38bc32794552dd2e8e5d5f4a4ebedbee771be25715ccb806c743b9b06df7f6\",\"logIndex\":\"0x2\",\"removed\":false},{\"address\":\"0xa70f993d5dd72dd8567b3da7ed1a945a39ab44b1\",\"topics\":[\"0xee9ff4d977958c645eb6c38f9c80e3e0fea7031421dbba4c206f972150ad43e8\",\"0x000000000000000000000000858af434578c5bfb3bd56bfa10d58249fde094b1\"],\"data\":\"0x0000000000000000000000000000000000000000000000000000000000000066\",\"blockNumber\":\"0x186a6\",\"transactionHash\":\"0x1a79a45233f94608881059d0c3fc176d9a5fde84c69aaf7997ca207

...

e3e0fea7031421dbba4c206f972150ad43e8\",\"0x000000000000000000000000858af434578c5bfb3bd56bfa10d58249fde094b1\"],\"data\":\"0x000000000000000000000000000000000000000000000000000000000000006a\",\"blockNumber\":\"0x2e6e7\",\"transactionHash\":\"0x94e8f8792dba145e23b4181d2a546258d08db4853f6a4c01deff6ad70f3777f7\",\"transactionIndex\":\"0x1\",\"blockHash\":\"0x5bbb0ce376adf03112063b72d062a4fd516bdc4dec13eab8601e3c48a3b035e8\",\"logIndex\":\"0x5\",\"removed\":false},{\"add"
    at Object.InvalidResponse (/Users/x/Desktop/Code/test/node_modules/web3-core-helpers/src/errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/x/Desktop/Code/test/node_modules/web3-providers-http/src/index.js:75:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/x/Desktop/Code/test/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/x/Desktop/Code/test/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/x/Desktop/Code/test/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/x/Desktop/Code/test/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

However when setting startBlockNumber to 0, we get the error

Error: Invalid JSON RPC response: ""

If querying just 1000-2000 blocks to the latest block number, everything works fine.

Why is this error happening, and what can we do to get the correct results?

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.