Based on your comment, I can only assume that your question's correct title is: "how to hardcode an address in the substrate runtime".
A similar question has been answered here. To briefly recap here, the AccountId type that is known inside the pallets is only bounded to these traits: https://github.com/paritytech/substrate/blob/master/frame/system/src/lib.rs#L195
So it is a bit harder to hardcode one inside a pallet, albeit still possible. A more sensible way would be to inject the hardcoded account into your pallet from outside as a configuration.
First, your config trait need to accept a type that contains this account:
trait Config: frame_system::Config {
// A type that can deliver a single account id value to the pallet.
type CharityDest: Get<<Self as frame_system::Config>::AccountId>
}
Then, to use it, you'd simple do:
// inside the `impl<T> Module<T>` or `impl<C> Pallet<T>` or `decl_module` where `T` is in scope.
some_transfer_function(T::CharityDest::get(), amount);
Finally, in your top level runtime file you can hardcode the AccountId and pass it in through, as such:
parameter_types! {
pub CharityDest: AccountId = hex_literal::hex!["hex-bytes-of-account"].into()
}
impl my_pallet::Config for Runtime {
type CharityDest = CharityDest;
}
Alternatively, you can also use the fact that the AccountId
type of most runtimes is AccountId32
, which implements Ss58Codec
, meaning that it has a bunch of useful functions to convert from the Ss58 string to the account, so you can do something like
parameter_types! {
pub CharityDest: AccountId = AccountId::from_ss58check("AccountSs58Format").unwrap()
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…