StateBackend::storage calls return None when the StorageKey is empty.

If OnEmpty was set, one can decode and parse the RuntimeMetadata to access the default value and fall back to it.

  • Is there any alternative method to get a storage default value from the client?
  • In other words, are OnEmpty values persisted exclusively on the RuntimeMetadata?

1 Answer 1


No, there is no way to get the storage default value. If you want something like this, you will need to make the default value "shareable" between the node and runtime.

struct MyType(u32);

const MY_TYPE_DEFAULT: u32 = 10;

impl Default for MyType {
    fn default() -> Self { Self(MY_TYPE_DEFAULT) }

Something like this. Then you can also just use MY_TYPE_DEFAULT in the node for example.

  • It seems you would also be able to access this default value by having the client import the pallet crate, and get it from the storage definition, right?
    – Shawn Tabrizi
    Feb 15, 2022 at 19:23
  • 1
    Yes, that would also work. I mean, in general importing runtime stuff into the client should be prevented. Substrate is build in the way of having the runtime and client separate. Especially to ensure that the runtime can be upgraded without breaking the client. Here, this would also introduce such a shared "state", but if you force yourself to put the shared item into some different crate. So, you hopefully not break it too easily.
    – bkchr
    Feb 15, 2022 at 19:38

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.