How can I convert a Substrate address to an Etherum address?
There is an EVM to substrate address conversion that Edgeware provides: https://edgewa.re/keygen
How can I convert a Substrate address to an Etherum address?
There is an EVM to substrate address conversion that Edgeware provides: https://edgewa.re/keygen
The Ethereum address correspond to the last 20 bytes of the keccak-256 hash of the (decompressed) secp256k1 public key.
For example, given the following key generated via subkey tool:
❯ subkey generate --scheme Ecdsa Secret phrase `normal whale earth envelope wash bench drip latin please inform crisp congress` is account: Secret seed: 0x6c51a7f71537a60e666288a292ceabf322202af75e39bc34fd10f576cee489a5 Public key (hex): 0x025f13d211338f64fcc941e80b9d71929c38a7147762541da4123de45cedb0b312 Account ID: 0x211e23eda1f535feb3abd690513a0c2731c4bb9940aad59f0fb3c8abe89308e1 SS58 Address: 5Cp8PdGYPGe2Vc5WLb4eUmbeuhxuDjPSQcpyWgVSjh97D9sR Public key is given in compressed form:
Compressed: 0x025f13d211338f64fcc941e80b9d71929c38a7147762541da4123de45cedb0b312 Decompress it
Decompressed: 0x045f13d211338f64fcc941e80b9d71929c38a7147762541da4123de45cedb0b31290c16565dbc3c937fd1d9cf4ecc8ad489551a7d608ec5c649bec747183334754 Compute the Keccak-256 of the decompressed key (excluded the first byte (0x04))
Keccak-256: 0x09ed410a80b44d0a8c3e7e1fd924abdb51e253b19f69fd8114fe6d9a1794d2cf The last 20 bytes is the Ethereum address
Eth Address: 0xd924abdb51e253b19f69fd8114fe6d9a1794d2cf Said that, if instead you only have a Substrate AccountId (without the public key) it is not possible to convert it to the corresponding ETH address.
The reason is that the AccountId is the result of a hash applied to the PublicKey (+ some other data) and thus it is not possible to revert it in order to recover the public key (and apply the procedure I've described above).
Here is a code snip doing the conversion in the Substrate Beefy pallet: