reactjserror-handlingethereumsmartcontractsmodifier

How to get modifier error message from a ETH smart contract?


I'm working on a web3 project with React and a contract that is deployed on the Rinkeby Testnet. I'm on purpose sending requests that will not succeed to do and confirm however capture the revert messages and show the knowledge within the browser. When testing a contract on Remix I notice if a method doesn't pass a modifier you truly see the error message shown within the window below the contract code.

When I call the contract from the one that is not a whitelist address, in the console I get this message:

call to Contract.doStuff errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Reason provided by the contract: "Your wallet address is not yet whitelisted.". Debug the transaction to get more information.

But in React UI, in the console I get this message:

{
  "blockHash": "0x6c36210443eb483cb5bf880da03c51611a771e3452875989084c48d8ea3bbc48",
  "blockNumber": 10247168,
  "contractAddress": null,
  "cumulativeGasUsed": 7066125,
  "effectiveGasPrice": "0x9502f911",
  "from": "0x4e824b1b274beb70f4205afc2c6bcb8797f770ca",
  "gasUsed": 30249,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0x0cae9c086399b6fdcda84ad9b1072933a87f38f9",
  "transactionHash": "0x1e8d71b3811f6c310819ec80e95c43140fd10c79cb3d017299c161dbde670198",
  "transactionIndex": 9,
  "type": "0x2",
  "events": {}
}
    at Object.TransactionError (errors.js:90:1)
    at Object.TransactionRevertedWithoutReasonError (errors.js:101:1)
    at index.js:437:1

Solution

  • Coming back here and having learned a lot more. Here I created a library and I hope this will help everyone.

    Here is the link: Web3 Errors Extract