ethers.js: Metamask updates seem to have broken some functionality in the Contract API in ethers

I’ve created this codesandbox to reproduce (works with metamask on mainnet or rinkeby, all that is needed is a small ETH balance to test) https://ott4i.codesandbox.io/

The bug happens with all Contract interactions, but in the above test, the user tries to approve the null address to transfer 5 wei of WETH.

Expected behavior: After submitting the transaction, you should see the step signature successful, awaiting mined transaction listed, and after mining, you should see the step transaction mined listed

Observed behavior: After submitting the transaction, the promise for the successful signature doesn’t resolve. However, when the transaction is mined both promises resolve at once and signature successful, awaiting mined transaction and transaction mined display simultaneously

You can change the ethers.js version in package.json, it seems to happen with all recent versions (including the new v5 beta). This started happening in one of our codebases that had no changes in the past couple weeks, so I believe it’s because of updates that metamask has rolled out.

Please let me know if you have any other questions.

Thanks, Sam

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

One of my recently released projects also suffers from this issue. I’ll be pinging the MM team again this week. 😃

If you do not need the transaction (only the hash), you can use the UncheckedJsonRpcSigner. Keep in mind that when deploying contracts, you will need to wait until the transaction is mined before you can get the Contract Address, and things like that.

In v5 this class is built-in. To get an UncheckedSigner, use provider.getUncheckedSigner(addressOrIndex) instead of provider.getSigner(addressOrIndex). Or if you already have a JsonRpcSigner, you can call signer.connectUnchecked() which will return a new Signer which does not poll.

The TransactionResponse from an UncheckedSigner will only have the hash available, all other properties will be null, but the .wait() method will work, which will work as normal, returning the receipt.

@cloudonshore Thanks! Yes, I’ve already sent a quick note regarding this to the MetaMask peeps last week, to see what they think. 😃

I suspect this is not an issue with MetaMask at all, but something INFURA likely recently added (possibly as an anti-DDoS metric). Regardless, it is something MetaMask has tentatively agreed to address, since it is somewhat simpler (and efficient) for them to implement anyways.

@danfinlay I’ve forwarded the state logs to that support email

@ricmoo So I went and sequentially installed all the versions between 6.4.1 and 6.0.0 and none of them fixed the issue. I also tried using older versions of ethers.js. I then thought what the other variable in the system was and I decided to try switching out the default geth node and voila! That fixed it!

Instead of the default rinkeby provider in metamask I used the custom RPC https://geth-rinkeby.airswap-api.com which is our rinkeby geth node at AirSwap. That fixes the issue. I will also share this comment on the thread on their repo so they are aware.