To ensure the wrapped token is bridged into the destination chain (in this case, C-Chain) you'll need to deploy a remote contract that implements the IERC20Bridge
interface, as well as inheriting the properties of TeleporterTokenRemote
. In order for the bridged tokens to have all the normal functionality of a locally deployed ERC20 token, this remote contract must also inherit the properties of a standard ERC20
contract.
avalanche blockchain describe myblockchain
+-------------------------------------------------------------------------------------------+
| TELEPORTER |
+---------------+------------------------------+--------------------------------------------+
| Local Network | Teleporter Messenger Address | 0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf |
| +------------------------------+--------------------------------------------+
| | Teleporter Registry Address | 0x82EeEf8e31D4Bf95916219D7949D66c468Ac0681 | // [!code highlight]
+---------------+------------------------------+--------------------------------------------+
Most other environment variables we will need are already set in the devcontainer.
export TELEPORTER_REGISTRY_L1 = 0x82EeEf8e31D4Bf95916219D7949D66c468Ac0681
Get the Source Blockchain ID
in hexidecimal format from the output of avalanche blockchain describe myblockchain
above, which in this example is the BlockchainID of your Avalanche L1:
+---------------------------------------------------------------------------------------------------------------+
| MYBLOCKCHAIN |
+---------------+-----------------------------------------------------------------------------------------------+
| Name | myblockchain |
+---------------+-----------------------------------------------------------------------------------------------+
| VM ID | qDNV9vtxZYYNqm7TN1mYBuaaknLdefDbFK8bFmMLTJQJKaWjV |
+---------------+-----------------------------------------------------------------------------------------------+
| VM Version | v0.6.9 |
+---------------+--------------------------+--------------------------------------------------------------------+
| Local Network | ChainID | 1 |
| +--------------------------+--------------------------------------------------------------------+
| | SubnetID | 2AKbBT8jFUfUsUJ2hhRiDUnAAajJdNhTKeNgEe3q77spMj1N8F |
| +--------------------------+--------------------------------------------------------------------+
| | Owners (Threhold=1) | P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p |
| +--------------------------+--------------------------------------------------------------------+
| | BlockchainID (CB58) | 2EzvQgth5D5aZ81gmF13TsA61c2zduHWqszYPVvzzvRWZXcQgA |
| +--------------------------+--------------------------------------------------------------------+
| | BlockchainID (HEX) | 0xa37b5143f12ecf020ec893e4a8f48159e470b47fd9ff293ab0a808be47a4f67c | // [!code highlight]
+---------------+--------------------------+--------------------------------------------------------------------+
export SOURCE_BLOCKCHAIN_ID_HEX =< BlockchainID ( HEX ) >
Using the forge create
command, we will deploy the ERC20TokenRemote.sol
contract, passing in the following constructor arguments:
Interchain Messaging Registry Address (for C-Chain)
Interchain Messaging Manager (our funded address)
Source Blockchain ID (hexidecimal representation of our Avalanche L1's Blockchain ID)
Token Home Address (address of NativeTokenHome.sol deployed on Avalanche L1 in the last step)
Token Name (input in the constructor of the wrapped token contract )
Token Symbol (input in the constructor of the wrapped token contract )
Token Decimals (uint8 integer representing number of decimal places for the ERC20 token being created. Most ERC20 tokens follow the Ethereum standard, which defines 18 decimal places.)
forge create --rpc-url myblockchain --private-key $PK \
lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \
--constructor-args "( ${TELEPORTER_REGISTRY_L1} , ${FUNDED_ADDRESS} , ${C_CHAIN_BLOCKCHAIN_ID_HEX} , ${ERC20_HOME_C_CHAIN} , 18)" "TOK" "TOK" 18
Note the address the remote contract was "Deployed to".
export ERC20_TOKEN_REMOTE_L1 =< "Deployed to" address >
After deploying the bridge contracts, you'll need to register the remote bridge by sending a dummy message using the registerWithHome
method. This message includes details which inform the Home Bridge about your destination blockchain and bridge settings, eg. initialReserveImbalance
.
cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_L1 \
"registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)"
You can increase/decrease the numbers here as per your requirements. (All values are mentioned in wei)
cast send --rpc-url local-c --private-key $PK $ERC20_C_CHAIN \
"approve(address, uint256)" $ERC20_HOME_C_CHAIN 2000000000000000000000