Skip to content

Instantly share code, notes, and snippets.

@shekohex
Created July 26, 2023 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shekohex/4f04f221af64481992d2fa42feec58b0 to your computer and use it in GitHub Desktop.
Save shekohex/4f04f221af64481992d2fa42feec58b0 to your computer and use it in GitHub Desktop.
Convert EVM Address to Substrate address
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