2

During a storage migration I want to add few SS58 Address in one storage. How to hardcode it in migration script?

1 Answer 1

2

See this tutorial on Substrate for the basics about migrations Basic storage migration, in this tutorial there is an example where it modifies the storage of a pallet (Nicks pallet) to include both a first name and an optional last name. The script has to transform the values to the new storage.

Your case is easier because if I understand correctly you just want to add some accounts into an storage. To see how to hardcore the an address, see this SE previous question: How to hardcode an address in the substrate runtime?.

A simple version of your code will look something like:

fn on_runtime_upgrade() -> frame_support::weights::Weight {
            let onchain_version = Pallet::<T>::on_chain_storage_version();
            if onchain_version < your_version {
                let account_hardcoded = AccountId::from_ss58check("account_hardcoded").unwrap();
                <YourStorage<T>>::put(account_hardcoded);
                // Return the weight consumed by the migration.
                T::DbWeight::get().reads_writes(1, 1)
            } else {
                log::info!(target: LOG_TARGET, "MigrateToV1 should be removed");
                T::DbWeight::get().reads(1)
            }
        }

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.