// 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();

    // ...

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

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

1 Answer 1


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 that you have read and understand our privacy policy and code of conduct.

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