2

I get the following error when trying to convert my frame_system::Config::AccountId to a MultiAddress.

expected enum `MultiAddress<sp_runtime::AccountId32, ()>`
   found enum `MultiAddress<<T as frame_system::Config>::AccountId, _>`
consider constraining the associated type `<T as frame_system::Config>::AccountId` to `sp_runtime::AccountId32`

Here is the code that fails to create a MultiAddress from the AccountId.

Self::ensure_pallet_enabled()?;

let staker = ensure_signed(origin)?;

let location: MultiLocation = MultiLocation {
    parents: 1,
    interior: Here,
};

let create_nomination_pool =
                RuntimeCall::NominationPools(pallet_nomination_pools::Call::<
                    polkadot_runtime::Runtime,
                >::create {
                    amount: 10000,
                    root: MultiAddress::from(staker),
                    nominator: MultiAddress::from(staker),
                    bouncer: MultiAddress::from(staker),
                });

Here is the type of my frame_system::Config::AccountId.

pub type AccountId = <<Signature as sp_runtime::traits::Verify>::Signer as sp_runtime::traits::IdentifyAccount>::AccountId;

1 Answer 1

2

You can add a trait to do this.

#[pallet::config]
trait Config: frame_system::Config {
  AccountIdConvertor: AccountIdConvertor<Self::AccountId>;
}

trait AccountIdConvertor<A> {
  fn to_32(a: A) -> AccountId32;
}

#[pallet::call]
fn c(origin: OriginFor<T>) {
  let a = ensure_signed(origin)?;
  let a_32 = T::AccountIdConvertor::to_u32(a);

  ..
}

Or you can limit only accountid32 chain can use this pallet.

#[pallet::config]
trait Config: frame_system::Config<AccountId = AccountId32> {}

..
3
  • Won't I need to implement the AccountIdConverter::to_32 method for the frame_system::Config::AccountId?
    – Snowmead
    Jun 1, 2023 at 18:14
  • Nope, you should define a struct at runtime level, and implement this trait for it. Finally, pass this struct to the youpallet::Config::AccountIdConvertor. Jun 3, 2023 at 0:39
  • Is there a public implementation of AccountIdConverter that we can look for reference? Aug 2, 2023 at 5:55

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.