web3js – Understanding Why Wallet Address from etheres.Wallet.createRandom() Is Identical on Different Chains

etherethers.jsetherscanpolygonweb3js

I have created a Wallet with etherJS using below API:

 const wallet = ethers.Wallet.createRandom();

After I import the wallet.privateKey into metamask, I found the wallet address is exactly same on Ethereum, BSC and Polygon.

I did a little bit research and found this answer https://ethereum.stackexchange.com/a/127273/109976, which mentioned that some times the address will be different on different chains when the wallet is created with code, like Polygon and Ethereum.

But I can see the wallet address is same on polygon mainnet and ethereum mainnet.

I am bit confused and will appreciate that if anyone could help me out with these doubts:

  1. why the wallet address is exactly same on those chains, and is it always the same?

  2. How do I tell if the which chain will have different address with the same private key?

Best Answer

With the same private key you will always get the same address in BSC, Polygon, ETH because they use the same address encoding scheme. In particular it's the last 20 bytes of the Keccak-256 hash of the public key and adding 0x to the beginning. Although they are all the same, the difference is the chainId in your transaction, it will state clearly which blockchain you want to use the account for. IMO, it is more convenient to use the same address on multiple blockchains sharing the same private key, although it will cause some risk when you lose the private key you will lose assets on all the blockchains. About finding blockchains having the same address encoding scheme like Ethereum, you can take a look at this list, most (not all) chains there have similar address encoding scheme to Ethereum (and read each blockchain's website to figure out more)

Related Topic