2

Let's say we have a smart contract test with a function foo() and a modifier so that only the contract owner can call this function.

Now we have a front-end with a user that is not the contract owner and is calling this function: the user will see the following alert in Metamask before confirming the transaction:

ALERT: Transaction Error. Exception thrown in contract code.

My question: is there a way to capture the error reason from the front-end to show the user why the transaction will fail? it looks like Metamask is "pre-launching" the transaction and detecting that some condition will fail (either require, out of gas, etc).

The closest thing I've been able to do from the front-end is to catch the error after the transaction has failed:

    await test.methods
        .foo()
        .send({ from: wallet.account })
        .on('error', (err: any) => {
            console.log('Error description: ', err);
            return;
        });

And even this way, the error description is just showing false in the status field. The goal would be to show the user why the transaction will fail before actually launching such a transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.