I recall there being a method to create a "const" storage outside of a pallet. You have the flexibility to assign any prefix. However, I can't remember where I came across this information. Could you please guide me on how to accomplish this?

1 Answer 1


The only thing that comes to mind from your description is the storage_alias. It can have three different kind of prefix and can be declared outside of pallets (actually anywhere).

The standard version when a pallet storage should be addressed looks like this. It is useful for writing migrations from/to pallets:

pub type PageIndex<T: Config> = StorageValue<Pallet<T>, PageIndexData>;

Now it is also possible to use another prefix, eg:

pub type PageIndex = StorageValue<MyPrefix, PageIndexData>;

Or making it entirely runtime dependant such that it can change at any time. For example when DynamicName implements Get<&'static str>:

pub type PageIndex = StorageValue<DynamicName, PageIndexData>;

Otherwise there is parameter_types, but it cannot take a custom prefix.

  • How does the b":code" work? Use sp-io to write the db directly?
    – AurevoirXavier
    Commented Nov 9, 2023 at 0:26
  • Exactly. This is why it does not have any metadata. See the key definition here and the write in System. This was done before any storage_alias existed. Commented Nov 9, 2023 at 12:18

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.