executeFunction - show Metamask window even if transaction is going to fail

Hello, after using web3.js library in the Moralis version 0.0.184 I started to use the newest Moralis versions with ethers.js and for the contract write functions I’m using Moralis.executeFunction.

It’s working properly but I just noticed that if there is an error at the beginning of the transaction (e.g. insufficient funds) it’s no more “managed by” Metamask, but it’s thrown an error that I can catch.

So the old flow was:
click on a button (e.g. minting button) => Metamask popup opens => if there is a problem with the contract (e.g. is paused, or the user has not funds) directly Metamask is telling the user that the transaction is going to fail or can’t be performed

New flow:
click on a button (e.g. minting button) => If there is a problem with the contract as above, an error is thrown and can be caught, but the Metamask popup doesn’t appear anymore

In this way I have to manage the error to show a modal to the user, it’s ok but I preferred when this was directly managed by the wallet.

Is there any way the old flow behavior can be restored?

Thank you

I don’t know if there is a way to restore the old behavior. It may be something related to the usage of ethers.

I imagined, but I’ve seen a similar topic here of around 1 year ago

As an user pointed out there

When I go to make a transaction on etherscan, I get the error in the metamask UI. I would like to mimic that experience

It’s basically what I’d need. Since I’m using Moralis.executeFunction, is there any opportunity to force the error in the metamask UI instead of catching it?

Thank you

You may have to use web3.js directly to get this back instead of executeFunction (ethers.js). Have you tried setting a gas limit as suggested (this still requires using ethers.js directly)? I’m not sure if there is anything else to try given that the ethers.js author didn’t suggest anything else.

1 Like

Hello, searching on the forum I think that it’s not possible with executeFunction to set a gasLimit e.g. [Allow to set gas limit in "Moralis.executeFunction" options](https://This topic)

I’ve tried directly with ethers.js but it didn’t work as well. I’ll try switching again to web3 or managing directly the errors with my UI, even if I think it would not be the correct behaviour, already the wallets do this job.

If there are other suggested approaches are more than welcome, thank you

It’ll be fine managing the errors as you’ve mentioned as you can throw some warning or alert to your client in the onError function or in the catch block

1 Like