We can use subkey
to generate a sr25519 key pair, we will get the Secret Seed
and Account ID
, Account ID
is the substrate address
(let us call it as addressA
), and you can genarate the private key using this secret seed.
Besides, we can import the generated private key into Metamask and get a corresponding evm address
(call it addressB
), but actually these 2 addresses are address of 2 different account.
We can do a experimentation:
- using the evm address we get above to get 10 testnet ATA from faucet
- import the substrate address into blockchain explorer
- get balance of the imported account in step#2(Developer -> Chain state -> system -> account)
We will find tha balance of the imported account is not 10, actually is 0 if it is a new generated account
Then you can use code below to calculate a substrate address from the evm address, <evm address>
is the address in Metamask without leading 0x
use blake2::VarBlake2b;
use blake2::digest::{Update, VariableOutput};
use hex;
fn main() {
// create a Blake2b object
let mut hasher = VarBlake2b::new(32).unwrap();
// write input message
let mut data = [0_u8; 24];
data[0..4].copy_from_slice(b"evm:");
data[4..24].copy_from_slice(&hex::decode("<evm address>").unwrap());
hasher.update(&data);
// read hash digest and consume hasher
let _res = hasher.finalize_variable(|res| {
println!("{:?}", hex::encode(&res[..]));
});
}
you will get a string like 65f5fbd10250447019bb8b9e06f6918d033b2feb6478470137b1a552656e2911
by running code above, then come back to blockchain explorer, paste the string here(we will get a another address, call it addressC ) and call account function:
you will find that balance of this account is 10 ATA(or 10 BATA)
The result verifies that actually addressA
and addressB
are 2 different account in our chain, addressB
and addressC
are same account in our chain.
Currently, assume that someone have some ata in his evm address account, and he want to interact(send extrinsics) with our chain, it is impossible because he doesn't know the private key of corresponding substrate address.
So maybe we need to change the mapping methods in evm pallet, take the previous example, we should mapping addressA
to addressB
enhancement