Getting the error:

the trait MaxEncodedLen is not implemented for SomeStruct

If I add MaxEncodedLen to the #[derive()] list it changes to this:

error[E0599]: no function or associated item named max_encoded_len found for struct frame_support::dispatch::Vec<u8> in the current scope --> /home/aely/substrate-node-template/pallets/template/src/lib.rs:42:9

How do I store a struct that has a Vec or is a string in js?


2 Answers 2


This is what ended up working.

How to store a string in substrate storage?

Instead of using

Struct {
    string_field: Vec<u8>


Struct {
   string_field: [u8; some_limit]

I also had to import MaxEncodedLength and add it to the #[derive()] list as well.


use can use BoundedVec<u8, ConstU32<128>> instead using the Vec<8> in the struct . if you need to use struct into the storage you have to use this macro with the storage :


Exmaple :

#[pallet::getter(fn storage)]
pub(super) type storage<T: Config> = StorageDoubleMap<

The BoundedVec<u8, ConstU32<128>> type signifies a vector of u8 elements with a bounded length, in this case, a maximum length of 128 elements. This construct is typical in Substrate-based blockchains to put an upper limit on the size of dynamic collections to ensure that they do not grow indefinitely, which could lead to performance issues or exploits.

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.