1

I'm new in the world of Ethereum and I'm building a app with node.js.

I'm using web3 1.0 and infura to connect to a contract and get all the logs for different events. I'm using the "getPastEvents" function from web3.

I'm getting this error time to time "Invalid JSON RPC response".

Right now, when I get this error, I just restart the app and if it passes good if not well i restart again... I'm putting a setTimout function so my app restart by itself. But because of that error, my app is crashing and doing an exit.

How can I handle this error ? any suggestion will be very appreciated.

0

There are some problems with web3 1.0 and events via Infura.

And since web3.js 1.0 is not yet released, the best advise is to use web3 version 0.2x.x.

Take a look at this on how to initiate an event listener on web3 0.2x.x

  • Thanks for the reply. Good to know... do you have any examples to be able to get past events in web3 version 0.2x.x. ? – fadmtl May 28 '18 at 15:30
  • Edited the answer with a link to a repo of mine, where I initiate the event listener in a web3 0.2x.x dapp. If you find this answer satisfactory, please mark it as such, it helps other people to find answers to their questions. Thank you. – bordalix May 28 '18 at 16:41
  • your code would be the same if i wanted to do it in node.js ? – fadmtl May 28 '18 at 18:05
  • it should work also with node.js. – bordalix May 28 '18 at 18:27
  • The event will fire inside the (err, res) => {...} so don't close it, and put your code inside the block ({}). – bordalix May 29 '18 at 6:07

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.