logoAcademy

Deploy a Remote Contract

Deploy the Token Remote on your own blockchain

ERC20 Remote

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.

First, get the Source Blockchain ID in hexidecimal format, which in this example is the BlockchainID of your Avalanche L1, run:

avalanche subnet describe myblockchain
export SUBNET_BLOCKCHAIN_ID_HEX=0x4d569bf60a38e3ab3e92afd016fe37f7060d7d63c44e3378f42775bf82a7642d

Source Blockchain ID is in the field: Local Network BlockchainID (HEX).

Do the same for the C-Chain:

avalanche primary describe

Destination Blockchain ID is in the field: BlockchainID (HEX).

export C_CHAIN_BLOCKCHAIN_ID_HEX=0x55e1fcfdde01f9f6d4c16fa2ed89ce65a8669120a86f321eef121891cab61241

Using the (forge create)[https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [ERC20Remote.sol](./NativeTokenHome.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/teleporter-token-bridge/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \
--constructor-args "(${TELEPORTER_REGISTRY_SUBNET}, ${FUNDED_ADDRESS}, ${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_BRIDGE_C_CHAIN})" "TOK" "TOK" 18

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

export ERC20_TOKEN_REMOTE_SUBNET=<"Deployed to" address>

Register Remote Bridge with Home Bridge

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_SUBNET "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)"

Approve tokens for the Home Bridge contract

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_HOME_C_CHAIN "approve(address, uint256)" $ERC20_HOME_BRIDGE_C_CHAIN 2000000000000000000000
Updated:

On this page

Edit on Github