0
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

error Unauthorized();

contract VendingMachine {
    address payable owner = payable(msg.sender);

    function withdraw() public {
        if (msg.sender != owner)
            revert Unauthorized();

        owner.transfer(address(this).balance);
    }
    // ...
}

How can I extract Unauthorized when the transaction reverts by using ethersjs?

1
  • When catch, the error result is roughly as follows: "0x3ccfd60b0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000e556e617574686f72697a65642829000000000000000000000000000000000000" ? Commented Sep 22, 2023 at 10:22

1 Answer 1

0

You can find a good answer in an article here: https://soliditylang.org/blog/2021/04/21/custom-errors/ and here: https://stackoverflow.com/questions/76550726/how-to-extract-error-message-from-transaction-using-ethers-js

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.