ERC-20 to ERC-20 Bridge
Transfer ERC-20 tokens between Avalanche L1s
Transfer an ERC20 Token → Avalanche L1 as Native Token
The following example will show you how to send an ERC20 Token on C-chain to an Avalanche L1 as a native token using Interchain Messaging and Foundry. This demo is conducted on a local network, but can be applied to Fuji Testnet and Avalanche Mainnet directly.
All Avalanche Interchain Token Transfer contracts and interfaces implemented in this example implementation are maintained in the avalanche-interchain-token-transfer repository.
If you prefer full end-to-end testing written in Golang for bridging ERC20s, native tokens, or any combination of the two, you can view the test workflows directly in the avalanche-interchain-token-transfer repository.
Deep dives on each template interface can be found here.
Disclaimer: The avalanche-interchain-token-transfer contracts used in this tutorial are under active development and are not yet intended for production deployments. Use at your own risk.
What we have to do
- Create an Avalanche L1 and Deploy on Local Network
- Deploy an ERC20 Contract on C-chain
- Deploy the Interchain Token Transferer Contracts on C-chain and Avalanche L1
- Register Remote Token with Home Transferer
- Add Collateral and Start Sending Tokens
Local Network Environment
For convenience the private key 56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027
of the default airdrop address is stored in the environment variable $PK
in .devcontainer/devcontainer.json
of the Starter-kit. Furthermore, the RPC url for the C-Chain local-c
and the Avalanche L1 with the name myblockchain
on the local network is set in the foundry.toml
file.
Avalanche L1 Configuration and Deployment
To get started, create an Avalanche L1 configuration named "myblockchain":
Your Avalanche L1 should have the following things:
- Interchain Messaging enabled
- CLI should run an AWM Relayer
- Upon Avalanche L1 deployment, 100 tokens should be airdropped to the default ewoq address (0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC)
- Native Minter Precompile enabled with either your admin address or the pre-computed Remote token address
Note: If you have created your Avalanche L1 using AvaCloud, you can add Remote Token address using the dashboard.
Finally, deploy your Avalanche L1:
The CLI will output addresses and information that will be important for the rest of the tutorial:
From this output, take note of the following parameters
- Funded Address (with 100 tokens),
- Interchain Messaging Registry on C-chain, and
- Interchain Messaging Registry on Avalanche L1
Set these parameters as environment variables so that we can manage them easily and also use them in the commands later.