I would like to know what are the ways and how we can retrieve the all items stored in a custom pallet

I was having data structured in this way

        Clone, Encode, Decode, Eq, PartialEq, Default, RuntimeDebug, MaxEncodedLen, TypeInfo,
    pub struct ProvidedConsent<BoundedString> {
        pub _id: BoundedString,
        pub user_id: BoundedString,
        pub business_id: BoundedString,
        pub consent: BoundedVec<Consent<BoundedString>, ConstU32<50>>,
        pub last_updated: u64,
        pub is_active: bool,
        pub is_deleted: bool,
        pub added_on: u64,

    #[pallet::getter(fn consents)]
    pub(super) type UserConsent<T: Config> = StorageDoubleMap<
        BoundedVec<u8, T::StringLimit>,
        ProvidedConsent<BoundedVec<u8, T::StringLimit>>,

        Encode, Decode, Clone, PartialEq, Default, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo,
    pub struct Consent<BoundedString> {
        pub key: BoundedString,
        pub is_accepted: bool,

I also got to know with polkadot.js we have a way , but for custom pallet how does it work https://polkadot.js.org/docs/api/start/api.query.other/#map-keys--entries

Also, we have Runtime API to collect values in StorageMap, we can use it in runtime

But, please can anyone explain how we can implement a retrieve list feature using polkadot.js and using runtime

2 Answers 2


In your case with PolkadotJS it will look like this:

const consents = await api.query.yourpallet.userConsent.entries();
consents.forEach(([key, consent]) => {

And in the Runtime:

yourpallet::UserConsent::<Runtime>::iter_values().map(|v| v.encode()).collect::<Vec<Vec<_>>>();

You can refer to https://polkadot.js.org/docs/substrate/storage on how to access storage from any pallet either it is custom or existing. Substrate already provides APIs for the same and can be called via api.query.<module>.<method>.

And if you want to access the storage from polkadot js explorer than you can go to Developer > Chain State > "pallet" https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fpolkadot-rpc.dwellir.com#/chainstate

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.