MoralisWeb3 / react-moralis

Hooks and components to use Moralis in a React app
MIT License
624 stars 166 forks source link

How to catch an EVM/Transaction error correctly #83

Closed dohomi closed 2 years ago

dohomi commented 2 years ago

New Feature Request

Checklist

Current Limitation

If an EVM error is being thrown if the user communicates with a contract through MetaMask then inside of NextJS the error is not being captured.

Is there any way to have a proper async error handling in place?

Feature / Enhancement Description

Add possibility to watch for errors of web3.ether.contract. The Transaction error is correct but I could not find a way how to handle the error.

Screenshot 2021-11-13 at 00 33 48
dohomi commented 2 years ago

Currently I am using following block to solve it, first I use .call and that seems to be catched correctly. .send does not seem to be able to show the error correctly :

try{
  await contract.methods.mint(selectedAmount)
                    .call({ value: contractDescription.getCurrentCost }) 
  await contract.methods.mint(selectedAmount)
                    .send({ value: contractDescription.getCurrentCost })
} catch(e){
  console.log("error is thrown while trying to ming..", e)
}
ErnoW commented 2 years ago

This is how web3.js works. The send call is successfully sent, but you will need to wait until it is confirmed or rejected. Check the docs from web3.js on how to do this properly: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#methods-mymethod-send

Will close this issue as it is related to web3.js, not react-moralis