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.

  • You are not able to connect to your node (I think you are using geth client). Commented May 15, 2018 at 11:13
  • What tools are you using (e.g., truffle, ganache, etc)? Commented May 15, 2018 at 11:19
  • I am deploying the contract to the Ropsten test network via Remix and setting the web3 provider to the Ropsten Infura node
    – noob_23
    Commented May 15, 2018 at 11:28
  • Infura doesn't support events using watch, you have to use subscribe from web3 v1.0 and the websocket endpoint.
    – Ismael
    Commented May 15, 2018 at 19:39

3 Answers 3


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)


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)

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();

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.

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