logoAcademy

Deploy a Remote Contract

Deploy the Token Remote on your own blockchain

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.

Get the Source Blockchain ID

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

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

Save the Source Blockchain ID

export SOURCE_BLOCKCHAIN_ID_HEX=0x4d569bf60a38e3ab3e92afd016fe37f7060d7d63c44e3378f42775bf82a7642d

Get the Destination Blockchain ID

avalanche primary describe

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

Save the Destination Blockchain ID

export C_CHAIN_BLOCKCHAIN_ID_HEX=0x55e1fcfdde01f9f6d4c16fa2ed89ce65a8669120a86f321eef121891cab61241

Deploy the Remote Contract

Using the 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

Save the Remote Contract Address

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

export ERC20_TOKEN_REMOTE_L1=<"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