Solidity has introduced Custom Error which is cheaper than requires (as I have read).

enter image description here

But when we get an error in web3(.js) functions like estimateGas we get Returned error: execution reverted as an error. No proper error to decode. I can see these errors in abi, but not sure how to detect in web3 app?

  • can you show your code pls? just looking at the custom errors, there's nothing defined that looks like it describes a gas problem so it seems reasonable to assume you don't have logic in your contract to detect that problem and revert with a custom error
    – sola24
    Commented Aug 21, 2022 at 14:26

1 Answer 1


I wrote an article in my blog about this topic. Using Web3.js to Parse Custom Error. It includes call, estimateGas and tx error. It should be helpful.

In your case, you can use this function to parse custom error.

import { Eip838ExecutionError } from 'web3';
import { decodeContractErrorData } from 'web3-eth-abi';

function parseInnerError(e, contract) {
  if (e?.innerError?.errorSignature) {
    return e.innerError;

  if (!e.innerError) {
    if (e?.data?.data.startsWith('0x')) {
      e.innerError = new Eip838ExecutionError(e.data);
  if (e?.innerError?.data?.startsWith('0x')) {
    decodeContractErrorData(contract._errorsInterface, e.innerError);
  return e.innerError;

And usage will be

try {
  await myContract.methods.sendWithError().estimateGas({ from });
} catch (e) {
  const innerError = parseInnerError(e, myContract);

Notice: RPC Node should also support custom error. For example, Arbitrum Goerli supports, but Ganache v2.5.4 not.

Tested at Web3.js v4.0.1 and Arbitrum Goerli.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.