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