2

I'm using ethers.js and I'm writing code to connect to MetaMask when the user clicks a "connect" button on my site.

The problem I'm having is that I'm unable to determine if the user dismisses the MetaMask popup.

I've tried multiple variations of code that includes using async/await and promises, I've tried using ethers.js, and I've tried using MetaMask directly. I've tried wrapping my code with a try/catch block and I've tried using .catch().

It's almost as if the request never resolves.

It would be ideal if I could avoid using the MetaMask specific API and instead rely on ethers to provide whatever the most standard Ethereum interface is.

UPDATE: After some additional testing I can confirm that calling

await ethereum.request({method: 'eth_requestAccounts'});

only throws if the listener dismisses a request to connect. However, the resulting promise appears to remain unresolved if the listener was not already authenticated and therefore dismisses the popup that asks for a password.

4
  • You could alternatively display a UI modal whenever no web3 instance is detected. Jun 12, 2021 at 5:25
  • in my case the ethereum instance is detected, it's just requesting that the user re-enter their password.
    – gxc
    Jun 12, 2021 at 5:49
  • Open the browser console and see if you get any logged error when you dismiss the modal. If you get one, you could catch it in the UI code. Jun 12, 2021 at 5:52
  • 1
    This may be a bug in MetaMask, I've filed a ticket: github.com/MetaMask/metamask-extension/issues/11280
    – gxc
    Jun 14, 2021 at 19:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.