0

I have the following on a MyLibrary contract:

struct MyStruct {
    uint256 id;
    address owner;
    address eventContract;
    uint256 price;
    TheState theState;
    bool exist;
    string tierName;
  }

function formatTokenURI(MyStruct memory self, ... more params)
    public
    pure
    returns (string memory)
  {

I have the exact same function in Contract X like so:

function formatTokenURI(MyLibrary.MyStruct memory tempStruct,...more params)
    public
    pure
    returns (string memory)
  {

Now, when I call formatTokenURI from Contract X, I input all the params and the struct I make it like this:

[1,"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47",26,0,true,"crazyname"]

And it goes throught successfully.

But if I deploy a MyLibrary contract and try to call directly the formatTokenURI function I get: Error encoding arguments: Error: invalid type (argument="type", value="MyLibrary.TheState", code=INVALID_ARGUMENT, version=abi/5.5.0)

I have literally tried everything (inserting/removing quotes, using uint8 as input for TheState params; but nothing seems to work.

When it comes from the context of the same contract the tuple needs to be formatted differently. Any ideas???

Thank you so much for your help!

1
  • Can you share all your smart contract code? Commented Jul 26, 2022 at 16:33

1 Answer 1

0

function formatTokenURI(MyStruct memory self, ... more params) would be like

struct MyStruct {
    uint256 foo;
    string bar; 
}

function func(MyStruct memory mystruct, uint256 a, bool b)

with the following input works:

[7, "name"], 11, false

so I guess what you're looking for is to enter the struct as an array followed by the other parameters so that would be

[1,"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47",26,0,true,"crazyname"], other parameters

1
  • Nope. Doesn't work. The error highlights 'MyLibrary.TheState' so I think the problem lies on what to put there. Being called from outside a Uint8 works as explained but inside the library it seems to require a different way of defining the enum. Commented Jul 25, 2022 at 19:24

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.