Is there any function inside MetaMask or Web3JS to detect if the node is down? For example, let say the private node that the user is connected to is down, how my app can know about it?

Steps to reproduce in local environment:

  1. Launch your Dapp in local mode
  2. Connect to a private node i.e. Ganache
  3. Unlock MetaMask
  4. Quit or kill the private node i.e. Ganache
  5. Go back to Dapp, check MetaMask

In above scenario, MetaMask doesn't produce/show any error to user mentioning the node is down. MetaMask still keeping a state of that node and assumes the node is still alive.

I try to handle this manually by creating a 'ping'-like function. But, due to the nature of CORS, that's not possible because in order to comply with CORS, it assume both Dapp and private node are on same protocol, host and port number. So, my 'ping'-like function didn't work.

So, my question here is, does MetaMask or Web3JS provide any function to call to detect if the RPC node is down/not reachable?

  • Web3 has web3.isConnected(), not sure if MetaMask support that method.
    – Ismael
    May 6 '18 at 2:35
  • @Ismael I'm aware of that function. But it's not working. I tried. May 6 '18 at 7:32

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.