I'm developing a Substrate-based blockchain and using StorageDoubleMap to store label details. The StorageDoubleMap is defined as follows:

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

I need to retrieve LabelsDetail using just the label_id (of type HashId<T>), without knowing the AccountOf<T>.

What are the best practices for this scenario? Is it possible to find the LabelsDetail using only label_id, or do I need to change my storage structure or use additional indexing?

2 Answers 2


You can use iter_prefix() from the StorageDoubleMap to iterate over values that share the first key. You can find one such example here


Does the on-chain logic really need to find this value itself or is verifying a valid position enough?

The problem is that this could incur an unbound storage iteration and slow down the chain. If this runs on a parachain there would be the chance that it halts when there are lots of entries in the map.
Maybe it is possible to find the entry off-chain and provide the index as witness argument to the extrinsic.

If this is not a problem for you, then the iter_prefix mentioned above is indeed possible.

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.