0
library MyLib {
    enum MyEnum {
        A, B
    }

    function f() public pure returns (MyEnum){
        return MyEnum.A;
    }
}

I want to return the enum in library. It is deployed as well, but revert on contract call. this is the error message. { "error": "Failed to decode output: Error: invalid type (argument="type", value="MyLib.MyEnum", code=INVALID_ARGUMENT, version=abi/5.5.0)" }

Help me..

1
  • It works well on contract instead of library. but i want to make it library.
    – nate
    May 17 at 12:00

1 Answer 1

0

Whereas each element in Enum is integer, you can come back from f() function uint type and cast Enum element in uint. You can see this example:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library MyLib {
    enum MyEnum {
        A, B
    }

    function f() public pure returns (uint){
        // MyEnum.A = 0;
        // MyEnum.B = 1;
        return uint(MyEnum.A);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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