Contract Error Messages

How do we get contract error messages?

  1. The contract allows a user to mint only once.
  2. If user/wallet mints again, the contract will show the error Exceeded mint limit.

The above two parts work perfects.

Here is a stripped down version of the code:

import { useMoralis, useWeb3ExecuteFunction } from "react-moralis";

export default function Mint() {
const constractProcessor = useWeb3ExecuteFunction();

const mintOptions = {
    contractAddress: contractAddress,
    functionName: "mint",
    params: {
      _season: 1,
      _mintVolume: 1,
    msgValue: 0,
    signingMessage: "Mint", 

async function mintNFT() {    
    await constractProcessor.fetch({
      params: mintOptions,
    }).then((success) => {
      console.log("Success: ", success);
    }).catch((err) => {
      console.log("Error: ", err);

return (
    <button onClick={() => mintNFT()}>Mint</button>

The first time a wallet mint’s it works perfects.

The second time the same wallet mints, the function goes through, but success is null.

The Metamask RPC shows the error in the console:

MetaMask - RPC Error: execution reverted: Exceeded mint limit.
{code: -32603, message: 'execution reverted: Exceeded mint limit.', data: {…}}

As you can see the contract does what it should, but the constractProcessor.fetch function is a success, when it should ideally by an error.

The problem is that visually in the FrontEnd I should show the user the reason why the contract hasn’t gone through.

How do I access this error message?
Shouldn’t the Moralis SDK expose these errors?

onError in your fetch should work for this. And you can use onSuccess and onComplete as well.

Your fetch will get to then because the request did go through and resolve, it just wasn’t successful.