Created
July 26, 2023 12:50
-
-
Save shekohex/4f04f221af64481992d2fa42feec58b0 to your computer and use it in GitHub Desktop.
Convert EVM Address to Substrate address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
blake2AsU8a, | |
encodeAddress, | |
} from "https://esm.sh/@polkadot/util-crypto"; | |
import { | |
hexToU8a, | |
stringToU8a, | |
u8aConcat, | |
} from "https://esm.sh/@polkadot/util"; | |
const input = Deno.args[0]; | |
if (!input) { | |
console.error("usage: deno run evmToSubstrate.ts <ETH_ADDRESS_HERE>"); | |
Deno.exit(1); | |
} | |
const addr = hexToU8a(input); | |
const data = stringToU8a("evm:"); | |
const res = blake2AsU8a(u8aConcat(data, addr)); | |
const output = encodeAddress(res, 42); | |
console.log({ input, output }); | |
// run using: | |
// $ deno run evmToSubstrate.ts <ETH_ADDRESS_HERE> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment