3

I'm working with pallet_evm of Frontier to support EVM, I want to map the Substrate account with the EVM account

    #[pallet::storage]
    pub type Mapping<T: Config> = StorageMap<_, Twox64Concat, H160, AccountId32>;

why did I change the AddressMapping of pallet_evm the EVM account balance dropped to 0

impl<T> pallet_evm::AddressMapping<AccountId32> for MyAddressMapping<T>
    where
        T: Config,
    {
        fn into_account_id(address: H160) -> AccountId32 {
            if let Some(account_id) = Mapping::<T>::get(address) {
                account_id
            } else {
                HashedAddressMapping::<BlakeTwo256>::into_account_id(address)
            }
        }
    }

and why the trait AddressMapping must have the value return rather than an option like this

pub trait AddressMapping<A> {
    fn into_account_id(address: H160) ->  Option<A>;
}

1 Answer 1

2

why did I change the AddressMapping of pallet_evm the EVM account balance dropped to 0

This AddressMapping uses to do conversation from H160 to substrate chain AccountId. Note the EVM account together with the corresponding substrate AccountId share the same balance module. As you stated the EVM account balance dropped to zero, the corresponding substrate AccountId's balance must also be zero too. Please ensure the convert is correct.

why the trait AddressMapping must have the value return rather than an option like this

According to the design in the frontier repo, An EVM account has a specific corresponding substrate AccountId. Can you explain when we need to return None for AddressMapping?

3
  • thank you, in case my H160 address has a balance of 10 Units, and the mapping address has 10 Units. So I have a total of 20 Units, right? Commented Mar 24, 2022 at 3:08
  • 1
    No, the evm account and mapping substrate account share the same balance pallet. You only have 10 Units. But two views to account address from outside. Commented Mar 24, 2022 at 3:12
  • now I understand my whole code issues. Commented Mar 24, 2022 at 3:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.