I have a storage in pallet

pub type Users<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, User>;

I need to iterate over all the storage map to check a field data inside the User structure.

1 Answer 1


StorageMap contains a function called iter() which returns a Iterator. So you can do something like this :

for (user_account_id, user_data) in Users::<T>::iter() {
    // Access the `User` structure using the user_account_id
    let user = user_data.ok_or("Error: User data not found")?;

    // Now you can check the field data inside the `User` structure
    if user.some_field == SomeValue {
        // Do something with the user's data

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.