You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converting between Substrate and EVM addresses can initially be a bit complicated, but once you understand the basic idea behind it, it becomes easy. Let's define the different scenarios we will be using:
Alice only has an account on Tangle EVM using the Metamask wallet.
Bob has an account on Tangle using the Polkadot.js wallet, and another account on Tangle EVM using the Metamask wallet.
Charlie only has an account on Tangle using the Polkadot.js wallet.
functionsubstrateToEvm(input: string): string{// Decode the address to the 32 bytes.constaccountId=decodeAddress(input);// Truncate it and take first 20 bytesconstres=accountId.subarray(0,20);// convert these bytes to hex.constoutput=u8aToHex(res);// The result is our EVM address.returnoutput;}
Convert EVM Address to Substrate
functionevmToSubstrate(input: string): string{// Convert EVM address to bytesconstaddr=hexToU8a(input);// Add a "evm:" prefixconstdata=stringToU8a("evm:");// concat the address and the prefix and hash them together// using blake2constres=blake2AsU8a(u8aConcat(data,addr));// encode the output and using 42 address prefix (substrate default)constoutput=encodeAddress(res,42);// The result is our Substrate address.returnoutput;}
Case 1: Sending from Substrate to EVM
Bob wants to send 100 TNT to Alice, but he does not have the 100 TNT on his EVM account in Metamask. Therefore, he decided to use his Tangle account in the polkadot.js wallet.
Alice's address is 0xa5fAA47a324754354CB0A305941C8cCc6b5de296.
Bob converts Alice's address to a substrate address using the evmToSubstrate function:
@shekohex you closed my issue (webb-tools/webb-docs#156) but as I see it, this information is totally different. I will merge these into a general account management section, if that's alright.
Yes! I closed the old one as it was in the wrong repo. Feel free to change this file or move it around.
This the new one: tangle-network/docs#7
Overview
Converting between Substrate and EVM addresses can initially be a bit complicated, but once you understand the basic idea behind it, it becomes easy. Let's define the different scenarios we will be using:
Let's assign the following values:
0xa5fAA47a324754354CB0A305941C8cCc6b5de296
5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
and0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990
5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y
Convert Substrate Address to EVM
Convert EVM Address to Substrate
Case 1: Sending from Substrate to EVM
Bob wants to send 100 TNT to Alice, but he does not have the 100 TNT on his EVM account in Metamask. Therefore, he decided to use his Tangle account in the polkadot.js wallet.
0xa5fAA47a324754354CB0A305941C8cCc6b5de296
.evmToSubstrate
function:5C9ysBsWKpw3D8MFaEauFgdtMPqboS64YNYHyu1rCynLyKMZ
.Case 2: Sending from EVM to Substrate
Alice wants to send 50 TNT to Charlie. However, Charlie only has a Substrate account that he controls in his Polkadot.js wallet.
5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y
.substrateToEvm
function.0x90b5ab205c6974c9ea841be688864633dc9ca8a3
.evm.withdraw("0x90b5ab205c6974c9ea841be688864633dc9ca8a3", 50 TNT)
.TASK CHECKLIST
The text was updated successfully, but these errors were encountered: