0

I get this error in the console whenever metamask is not installed in the browser.:

Uncaught TypeError: window.ethereum is undefined

It's all just a black screen

  • This? https://stackoverflow.com/questions/65802366/metamask-does-not-inject-window-ethereum-uncaught-in-promise-typeerror-canno – Dean James Jul 30 '22 at 15:11

1 Answers1

0

The simple solution is to wrap anything that references window.ethereum with an if:

useEffect(() => {
  if(window.ethereum) {
    window.ethereum.on('chainChanged', () => {
      window.location.reload();
    })
    window.ethereum.on('accountsChanged', () => {
      window.location.reload();
    })

    // Your extra code here
  }
})
Sean Whelan
  • 299
  • 4
  • 14