I have a scenario where I have to store multiple strings. For single string, we can use BoundedVec<u8, DescriptionLimit>, that's why I converted Vec<u8> into BoundedVec<u8, DescriptionLimit> to follow substrate best practices. But how do we store multiple strings?

Does it make sense to convert Vec<Vec<u8>> to Vec<BoundedVec<u8, DescriptionLimit>>?

Can someone please help me to answer this?

  • Can someone please help me?
    – Boleng
    Commented Mar 20, 2023 at 3:41

1 Answer 1


Interesting question, you are right to use BoundedVec to follow best substrate practices, I recommend this StackExchange questions to learn the difference between BoundedVec and Vec: When to use BoundedVec vs. WeakBoundedVec vs. Vec?.

I am not sure what is your data structure you want to store for the two strings but what I did was to use a struct. See the example of storing two strings: first name and last name:

#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen, PartialEqNoBound, RuntimeDebug)]
pub struct Nickname<T: Config> {
    pub first: BoundedVec<u8, T::MaxLength>,
    pub last: Option<BoundedVec<u8, T::MaxLength>>,

And then store the struct in your storage.

You can see the full example of the code here: https://github.com/substrate-developer-hub/substrate-node-template/blob/alexd10s/how-to-storage-migration-example/pallets/nicks/src/lib.rs#L113

Not the answer you're looking for? Browse other questions tagged or ask your own question.