logoAcademy

Deploy Token Remote for Multi-hop

Deploy and configure the ERC20TokenRemote contract on the second blockchain.

Deploy the Remote Contract

Using the forge create command, we will deploy the ERC20TokenRemote.sol contract, passing in the following constructor arguments:

  • Interchain Messaging Registry Address (for myblockchain2)
  • Interchain Messaging Manager (our funded address)
  • Source Blockchain ID (hexidecimal representation of Avalanche C-Chain)
  • Token Home Address (address of NativeTokenHome.sol deployed on Avalanche C-Chain in the Deploy a Home Contract section)
  • 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 myblockchain2 --private-key $PK \
lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \
--constructor-args "(${TELEPORTER_REGISTRY_CHAIN2}, ${FUNDED_ADDRESS}, ${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_C_CHAIN}, 18)" "TOK" "TOK" 18

Save the Remote Contract Address

Note the address the remote contract was "Deployed to".

export ERC20_TOKEN_REMOTE_CHAIN2=<"Deployed to" address>

Register Remote Contract with Home Contract

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 myblockchain2 --private-key $PK $ERC20_TOKEN_REMOTE_CHAIN2 \
"registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)"

Approve tokens for the Token Remote contract on myblockchain

Now that our ERC20TokenRemote contract is deployed and configured on myblockchain2, we need to prepare myblockchain for the token transfer. We will approve the ERC20TokenRemote contract to spend a certain amount of tokens on behalf of the sender.

You can increase/decrease the numbers here as per your requirements. (All values are mentioned in wei)

cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_L1 \
"approve(address, uint256)" $ERC20_TOKEN_REMOTE_L1 2000000000000000000000

On this page