Web3.js: [[email protected]] getPastEvents not working - {"code":-32603,"message":"request failed or timed out"}

Created on 3 Feb 2019  路  12Comments  路  Source: ChainSafe/web3.js

Expected behavior

Fetch all past events starting with a given block number

Actual behavior

It always return the following error:

Error: Node error: {"code":-32603,"message":"request failed or timed out"}

Downgrading back to [email protected] fixes the issue.

Steps to reproduce the behavior

const httpProvider = new Web3.providers.HttpProvider(infuraHTTPProviderURL);
const web3Instance = new Web3(httpProvider);
const coreContractInstance = new web3Instance.eth.Contract(coreABI, coreContractAddress);

coreContractInstance.getPastEvents('Birth', { fromBlock: 3768892 })
  .then((pastBirthEvents) => { debug('pastBirthEvents: %O', pastBirthEvents) })
  .catch((error) => { debug('error: ', error); process.exit(1) });

Error Logs

(node:379) UnhandledPromiseRejectionWarning: Error: Node error: {"code":-32603,"message":"request failed or timed out"}
    at Function.validate (/home/****/projects/*********/crypto-kitty-midwife/node_modules/web3-providers/dist/web3-providers.cjs.js:66:18)
    at /home/****/projects/*********/crypto-kitty-midwife/node_modules/web3-providers/dist/web3-providers.cjs.js:128:57
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:379) 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:379) [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.

Versions

[NPM, Node, Web3.js, OS, device...]

[email protected]
[email protected]
[email protected]
OS: Linux/Ubuntu 18.04

bug

Most helpful comment

The error indeed indicates that the node timed out when processing the request. However, the issue lies in the fact that with the recent library refactoring the contract address does not get added to the request parameters anymore! Thus, the events of all contracts on the chain will be queried, which is not hard to imagine to hit a timeout quickly 馃槂 Please reopen this issue.

All 12 comments

same for me.

@ironbyte are you using an Infura node?

@Sm00g15 Yep, I use an Infura WSS endpoint (wss://mainnet.infura.io/ws/v3/YOUR-PROJECT-ID)

@ironbyte same here. I also tried switching to an HTTP provider and no dice

I've tested it with my local test-net and different providers and it works without a problem.
screenshot 2019-02-06 at 12 52 01

Could you please add the address of the deployed contract you are testing it?

The same error did just appear. This error does only appear if the infura node does take to long until it got all the past event logs or when it can't find past logs. I would recommend to configure the timeout time of the provider with the option properties you can pass to the provider.

@ironbyte any luck on your end?

https://github.com/ethereum/web3.js/pull/2000 ; looks like this will fix it @nivida . Any idea when these changes will go live?

After updating the provider options I'm now hitting this error:

(node:37749) UnhandledPromiseRejectionWarning: Error: Connection error: Connection is not open on send()
    at /Users/smorgin099/projects/node_modules/web3-providers/dist/web3-providers.cjs.js:519:27

The error indeed indicates that the node timed out when processing the request. However, the issue lies in the fact that with the recent library refactoring the contract address does not get added to the request parameters anymore! Thus, the events of all contracts on the chain will be queried, which is not hard to imagine to hit a timeout quickly 馃槂 Please reopen this issue.

@Sm00g15 Hey, I've already downgraded back to [email protected]. Everything works on this version on my end. I will try a different provider on beta 41 later today. Will report if anything interesting happens.

@ironbyte @mistersandman @nivida - based on @mistersandman 's comment above I've opened up a new issue here: https://github.com/ethereum/web3.js/issues/2337

The error indeed indicates that the node timed out when processing the request. _However_, the issue lies in the fact that with the recent library refactoring the contract address does not get added to the request parameters anymore! Thus, the events of _all_ contracts on the chain will be queried, which is not hard to imagine to hit a timeout quickly 馃槂 Please reopen this issue.

@mistersandman can we fix this by manually adding the contract address to the parameters? My site has been down for days from this issue

EDIT: This issue was resolved by upgrading my Infura node to the latest V3 REST API

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabmontes picture gabmontes  路  3Comments

webersson picture webersson  路  3Comments

mishell-trickster picture mishell-trickster  路  3Comments

connectdotz picture connectdotz  路  3Comments

oktapodia picture oktapodia  路  3Comments