0

I’m trying to use the .watch() command on an event in my contract. Whenever I run the .js file, I’m presented with the following:

Error: Invalid JSON RPC response: “”

I’m not at my computer and can’t paste my .js file until later today, but what does this error suggest? It is displayed every time the file is executed. Could it be an issue with the contract instance or web3 itself?

Thank you in advance.

eth
  • 85,679
  • 53
  • 285
  • 406
noob_23
  • 11
  • 3

3 Answers3

1

As mentioned by Ismael, Infura doesn't support the use of .watch() events. The solution is to use the Infura websockets. Working code can be found here: Infura web3 provider for Events (.get & .watch)

noob_23
  • 11
  • 3
0

I also add issues using watch() on web3 to watch for events.

But I manage to solve them by using the alternative method (docs):

// Or pass a callback to start watching immediately
var event = myContractInstance.MyEvent([{valueA: 23}] [, additionalFilterObject] , function(error, result){
  if (!error)
    console.log(result);
});

For an event of this kind:

event singleNumber(uint256 number);

I get the value of it like this:

var event = myContractInstance.singleNumber({}, function(error, result){
  if (!error)
    var number = result.args.number.toNumber();
});
bordalix
  • 918
  • 7
  • 11
0

There is github thread about this response: https://github.com/trufflesuite/truffle/issues/852

According to this it's an issue with Infura and open handlers.

Arte
  • 1