Skip to content

Execution reverted (coult not decode custom error) #3785

Closed
@dennohpeter

Description

Ethers Version

6.0.3

Search Terms

decode error

Describe the Problem

Ethers V6 is unable to decode custom errors declared in solidity e.g error RevertWithCode(uint8 code); and errors msgs from function reverts in solidity e.g require(a > b, "a is not greater than b");

Reverts with Cannot assign to read only property 'invocation' of object 'Error: execution reverted (coult not decode custom error) or Error: execution reverted (unknown custom error)

Here is a link to verified contract on bsc testnet that you can use to reproduce the issue

https://testnet.bscscan.com/address/0xb8e82dd09afa2e5a16fb1f62e38b03edc20163e3#code

Code Snippet

import { Contract, JsonRpcProvider } from "ethers";

const Main = async () => {
  let provider = new JsonRpcProvider(
    "https://data-seed-prebsc-2-s1.binance.org:8545"
  );

  let abi = [
    {
      inputs: [{ internalType: "uint8", name: "code", type: "uint8" }],
      name: "RevertWithCode",
      type: "error",
    },
    {
      inputs: [],
      name: "number",
      outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
      stateMutability: "view",
      type: "function",
    },
    {
      inputs: [
        { internalType: "uint256", name: "a", type: "uint256" },
        { internalType: "uint256", name: "b", type: "uint256" },
      ],
      name: "requireRevert",
      outputs: [{ internalType: "bool", name: "", type: "bool" }],
      stateMutability: "pure",
      type: "function",
    },
    {
      inputs: [
        { internalType: "uint256", name: "a", type: "uint256" },
        { internalType: "uint256", name: "b", type: "uint256" },
      ],
      name: "revertWithCode",
      outputs: [{ internalType: "bool", name: "", type: "bool" }],
      stateMutability: "pure",
      type: "function",
    },
  ];

  let contract = new Contract(
    "0xB8e82DD09afa2E5A16Fb1f62e38B03EDC20163E3",
    abi,
    provider
  );

  let a = 6;
  let b = 4;
  // test revert with code
  //   console.log(await contract.revertWithCode.staticCall(a, b));

  // test require revert
  console.log(await contract.requireRevert.staticCall(b, a));
};
Main();

Contract ABI

[
    {
      inputs: [{ internalType: "uint8", name: "code", type: "uint8" }],
      name: "RevertWithCode",
      type: "error",
    },
    {
      inputs: [],
      name: "number",
      outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
      stateMutability: "view",
      type: "function",
    },
    {
      inputs: [
        { internalType: "uint256", name: "a", type: "uint256" },
        { internalType: "uint256", name: "b", type: "uint256" },
      ],
      name: "requireRevert",
      outputs: [{ internalType: "bool", name: "", type: "bool" }],
      stateMutability: "pure",
      type: "function",
    },
    {
      inputs: [
        { internalType: "uint256", name: "a", type: "uint256" },
        { internalType: "uint256", name: "b", type: "uint256" },
      ],
      name: "revertWithCode",
      outputs: [{ internalType: "bool", name: "", type: "bool" }],
      stateMutability: "pure",
      type: "function",
    },
  ]

Errors

TypeError: Cannot assign to read only property 'invocation' of object 'Error: execution reverted (coult not decode custom error)'
    at Interface.makeError (/<redacted>/client/node_modules/ethers/src.ts/abi/interface.ts:803:29)
    at Proxy.staticCallResult (/<redacted>/client/node_modules/ethers/src.ts/contract/contract.ts:345:48)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Proxy.staticCall (/<redacted>/client/node_modules/ethers/src.ts/contract/contract.ts:308:24)

Environment

node.js (v12 or newer)

Environment (Other)

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugVerified to be an issue.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions