I'd like to digest a data structure (a struct) with keccak256, but solc (0.4.23) tells me "Error: This type cannot be encoded."

Is there a good reason why can't solidity encode the struct? That looks like a straightforward job to me.

My current workaround is to manually call abi.encodePacked with each individual element of the structure, plus (as a header) a constant that lets me distinguish easily between different data structures. It's syntactically more cumbersome, and is not as type-safe as if I could hash the struct directly, but it does the job. Is that the right thing to do?

  • 1
    The function abi.encodedPacked is new since 0.4.22. My guess is that it was a change required for hashing structs and in the future they will add support for it using encodePacked. – Ismael May 26 '18 at 18:34

Your Answer

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

Browse other questions tagged or ask your own question.