Send XC20 Assets to EVM
Using XCM within the EVM environment is also simple as our network uses the XC20 interface, which maps the Assets pallet to an ERC20-compatible interface that EVM dApps can use.
XC20s and ERC20s are very similar, some distinct differences are to be aware of since XC20s are Substrate-based assets.
One of the XC20 specific features is the existence of asset's minimum-balance specific for each asset. Minimum-balance of an asset resembles an amount which is sufficient to allow the account's existence on the system without requiring any other existential-deposit. This feature's implication is that when transferring a certain amount of XC20 tokens, the amount actually transferred may be slightly greater in the case that the transfer would otherwise take the sender balance above zero but below the minimum balance. Must be greater than zero.
In addition, XC20s transactions done via the Substrate API won’t be visible from EVM-based block explorers such as Blocksout. Only transactions done via the Ethereum API are visible through those explorers.
XC20s can interact through an ERC20 interface, so they have the additional benefit of being accessible from both the Substrate and Ethereum APIs. This ultimately provides greater flexibility for developers when working with these types of assets and allows seamless integrations with EVM-based smart contracts such as DEXs, and lending platforms, among others.
First, let’s approach this at a high level, and then move on to a more technical example for dApps. Let’s say I want to move the KSM token from Kusama to
0xd2C6929A72e466213D1c2Df8359194784650A50e. From the Kusama side of things, the payload for sending the KSM tokens will be similar to the ones we used in the previous section. However, the
Beneficiary address (account ID) will be a mapped SS58 address of the recipient’s EVM address as that is the only address format that XCM can accept. You can read this article on how to create the mapped address. To keep things short, address mappings are:
Zag6jpFEU93xsEfczHbJucBUJAHMZFVsk4b3amvV5oXbJoo(with prefix 5 for Shiden/Astar)
- Public key:
To obtain the asset address for EVM, we need to get the token asset ID that we wish to use. In our case, we will be using KSM, which has the asset ID of
340282366920938463463374607431768211455. Now we need to convert the ID to hex and prefix it with
0xffffffff. The resulting address will be
0xffffffffFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF. We can directly load this address with the ERC20 interface and use it within our Solidity smart contract or use it within MetaMask.
Import Assets on MetaMask
On the previous page, we create a new asset and generated our asset contract address. Now let's add that contract address to MetaMask:
If you can't enter the decimals you haven't minted any assets. Make sure you minted your asset before going to this step.
- Make sure you are connected to the network you created your token.
- Click in your asset overview below on Import Tokens.
- Add the following:
- Token Contract Address
- Token Symbol
- Token Decimals
As you can see from the above image, importing an asset from the created address will correctly read the asset and add it to our wallet.
Send XC20 asset to EVM
Step 1: Convert Address
This part will be improved later to make it more builders friendly but we will explain it step by step. To send your newly created asset to EVM you first need to know your native mapped wallet to your EVM account. You can get that address by following these steps:
- Open our EVM to Substrate address converter.
- Switch to the H160 address scheme.
- Copy your EVM address from MetaMask and paste it into the Input address field.
- Your mapped native address will now be displayed.
Step 2: Send to EVM
For this part, we need to go back to Polkadot.js Apps. Make sure you are connected to the same network you created your asset.
In this guide, I want to send an amount of 1000 minted assets to my EVM account.
- Navigate to
Developer -> Extrinsics
- Use the
assets -> transferextrinsic.
- Select the account that has permission to send the asset.
- Enter your
asset id. See the previous page to know what asset id you need to enter For this guide, we are using
- Enter your native address in the
Idfield, the one you got with converting your EVM address to native.
- The last part is the amount, I want to send
1000tokens to my address. In my case, I enter
1000with 18 zeros because of using 18 decimals.
- Submit and sign the transaction.
- We are still working closely with our block explorers to map the new assets and be visible in our explorers.
- If you get an error with sending your tokens to another EVM account, please increase the gas fee.