TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

Could not parse type with internal type: undefined for custom structure

Open wbt opened this issue 3 years ago • 7 comments

I have some contracts using a library structure data storage, compiled using an older version of Solidity, but which throw an error asking me to make a report here.

In the libraryType.sol contract I have something like this:

library PersonLib {
    struct Data {
        bool   isActive;
        bytes  hashOfData;
        string handle;
    }
    function handle(Data storage self) public view returns (string) {
        return self.handle;
    }
    function markActive(Data storage self) internal {
        self.isActive = true;
    }
    //other getters & setters omitted
}

In other contracts, the library contract is imported and the type of a variable or struct member might be PersonLib.Data - sometimes, there are more than one of the same type in the same file (e.g. a Requester and a Contributor with wrapper functions similar to this:

    function requesterHandle() public view returns (string) {
        return requester.handle;
    }
    function updateRequesterHandle(string newHandle) public {
        emit RequesterHandleUpdated(newHandle);
        PersonLib.updateHandle(requester, newHandle);
    }

That works fine in Solidity, but when trying to generate types with TypeChain, that triggers an error like this:

Could not parse type: PersonLib.Data storage with internal type: undefined.

Please submit a GitHub Issue to the TypeChain team with the failing contract/library.

This error report is hereby filed per request. Hopefully I haven't missed something important when attempting to make it a minimal example for the report.

wbt avatar May 06 '22 22:05 wbt

Good morning everyone, I would be grateful if you could take charge of this issue. I've already used your library and was looking for projects to contribute to :)

StefanoGagliardi avatar May 18 '22 12:05 StefanoGagliardi

@wbt Hi, im start working on and i have few questions for you because i try to reproduce error without success. First of all on my fork you can see example contracts that i make:

  1. PersonLibrary.sol - Library Struct
  2. PersonLibraryConsumer.sol - Contract that consume library

Questions:

  1. Wich solidity version did u use for compile contracts? In the example i use 0.6.4
  2. What "target" parameter do you use during generation?
  3. Did you use integration plugin like for Hardhat?

Any other details are welcome as I had no problems generating the types in the example shown, I'm waiting, a greeting :)

StefanoGagliardi avatar May 21 '22 19:05 StefanoGagliardi

Thanks for your reply! My parameter is --target=truffle-v5 though on further investigation I see that the contracts JSON files were generated with Truffle v4, back when that was the latest version. This is for a TypeScript conversion of an application working with smart contracts deployed back when Truffle-v4 was current. I'll have to look into more details on that (on a later date) and see if I can get closer to a reproducing repo or a solution.

wbt avatar May 24 '22 14:05 wbt

I wound up changing Typechain and dependencies to use --target=truffle-v4 and it still produced the same errors.

wbt avatar May 24 '22 15:05 wbt

To answer other questions, Hardhat was not used or relevant at any point on these contracts, and the pragma statements specify either ^0.4.0 or ^0.4.24 which are equivalent; the latest available at the time of deployment.

wbt avatar May 24 '22 15:05 wbt

Thanks for your reply!

I got an error with this parameters: --target=truffle-v4 and Solidity version "0.6.4". I also try with solidity version "0.4.24" and same target --target=truffle-v4.

Both case i got this error: Error occured: Class extends value undefined is not a constructor or null. I was unable to get the same message you posted at the beginning of this issue.

  1. You got the same error?
  2. NB: More important, I was thinking where is the problem to generate Type using like target: "truffle-v5" ?
    "V5" is related to Typechain is not related with ethereum.
    Please try to compile Smart Contracts with this target and give me a feedback. If there are no compilation errors I would say close the issue as "truffle-v4" I think is deprecated, correct? @krzkaczor

StefanoGagliardi avatar May 24 '22 22:05 StefanoGagliardi

I'll see what I can do about generating a reproducing repo, but won't be able to work on that today.

wbt avatar May 25 '22 14:05 wbt