I am trying to create structure for ink smart contract but it fails on build giving error

Error msg

-the trait parity_scale_codec::WrapperTypeEncode is not implemented for ink_storage::Mapping<u32, [u8; 32]

-required because of the requirements on the impl of parity_scale_codec::Encode for ink_storage::Mapping<u32, [u8; 32]>

Struct details

#[derive(Default, Encode, Decode, Debug, SpreadLayout, SpreadAllocate)]
#[cfg_attr(feature = "std", derive(StorageLayout))]
pub struct Sample {
    pub roots: Mapping<u32, [u8; 32]>

Do I need to implement parity_scale_codec::Encode? Any advice or help here is much appreciated.

Thank you!!

2 Answers 2


Why do you want to Encode and Decode for a structure that contains Mapping? If you're going to implement PackedLayout - you can't. If you want to accept it as input - you can't. If you're going to return it - you can't=)

Encode and Decode are not implemented for Mapping because Mapping doesn't contain any information inside. It only provides get and insert methods to manipulate the storage.


You can derive this trait implementation automatically:

#[derive(scale::Encode, scale::Decode)]
struct my_struct {
  // …

If it still doesn't work it would be great if you could create a minimal contract that produces this error on https://ink-playground.substrate.io/ and share a link to that code.

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.