Would it be possible to clear a pallet storage with a call on a live chain ?

Precisely I would like to remove all contracts and code hash existing on my chain (as sudo).

1 Answer 1


It may be challenging to achieve that with a call.

You will need to send numerous extrinsics to accomplish it.

I suggest performing a runtime upgrade.

Refer to this link for more information: https://paritytech.github.io/substrate/master/frame_support/storage/migration/fn.clear_storage_prefix.html

use frame_support::migration;

migration::clear_storage_prefix(b"module name", &[], &[], None, None);

If your pallet storage is extensive, it is advisable to review the documentation mentioned above and adjust the values of None according to your specific situation.

  • Okay thanks ! What about weights on that function ? I need to return the used weights when doing a runtime upgrade and clear_storage_prefix() doesn’t calculate any weights used so do I need to check how many iterations was done and calculate weights from it ?
    – SailorSnoW
    Aug 20 at 13:53
  • You could count the delections and return the weight T::DbWeights::writes(x). Aug 20 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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