|
| 1 | +--- |
| 2 | +title: Example USDC as Native Token (DIY) |
| 3 | +description: Learn how to transfer USDC to a new Avalanche L1 and use it as a native token via ICTT. |
| 4 | +updated: 2024-09-03 |
| 5 | +authors: [owenwahlgren] |
| 6 | +icon: Terminal |
| 7 | +--- |
| 8 | +import { Step, Steps } from 'fumadocs-ui/components/steps'; |
| 9 | + |
| 10 | +In this section, you will learn how to transfer USDC from Avalanche’s C-Chain to a new Avalanche L1 using Interchain Token Transfers (ICTT) and set it up to act as the **native token** on the new L1. This guide will take you through the steps of configuring a local network environment, deploying the necessary contracts, and transferring tokens. |
| 11 | + |
| 12 | + |
| 13 | +<Steps> |
| 14 | +<Step> |
| 15 | +### Create a new blockchain and Deploy on Local Network |
| 16 | + |
| 17 | +Use the **Avalanche CLI** to create a new blockchain where you will deploy USDC as the native token. |
| 18 | + |
| 19 | + |
| 20 | +```bash |
| 21 | +avalanche blockchain create myblockchain |
| 22 | +``` |
| 23 | +```bash |
| 24 | +avalanche blockchain deploy myblockchain |
| 25 | +``` |
| 26 | +</Step> |
| 27 | +<Step> |
| 28 | +### Acquire USDC On Fuji C-Chain |
| 29 | + |
| 30 | +The address for USDC on Fuji C-Chain is [`0x5425890298aed601595a70ab815c96711a31bc65`](https://testnet.snowtrace.io/token/0x5425890298aed601595a70ab815c96711a31bc65). |
| 31 | +For convience we have already deployed a `TokenHome` to the C-Chain for USDC with the address [`0x546526F786115af1FE7c11aa8Ac5682b8c181E3A`](https://testnet.snowtrace.io/address/0x546526F786115af1FE7c11aa8Ac5682b8c181E3A) |
| 32 | + |
| 33 | +You can use the [Core Faucet to get some USDC](https://core.app/en/tools/testnet-faucet/?subnet=c&token=usdcc) on Fuji. |
| 34 | +```bash |
| 35 | +export USDC=0x5425890298aed601595a70ab815c96711a31bc65 |
| 36 | +export USDC_HOME_C_CHAIN=0x546526F786115af1FE7c11aa8Ac5682b8c181E3A |
| 37 | +``` |
| 38 | +</Step> |
| 39 | +<Step> |
| 40 | +### Deploy Interchain Token Transfer Contracts |
| 41 | +Set up the remote transferer contracts for transferring tokens between the C-Chain and the newly created L1. |
| 42 | + |
| 43 | +- `NativeTokenRemote` Contract on `myblockchain` |
| 44 | +```bash |
| 45 | +forge create --rpc-url myblockchain --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/NativeTokenRemote.sol:NativeTokenRemote --constructor-args "($TELEPORTER_REGISTRY_L1, $FUNDED_ADDRESS, $C_CHAIN_BLOCKCHAIN_ID_HEX, $USDC_HOME_C_CHAIN, 6)" "USDC" 100000000000000000000 0 |
| 46 | +``` |
| 47 | + |
| 48 | +_Note: When deploying the `NativeTokenRemote` contract on the L1, ensure that the **initial amount** matches the native token amount that was minted when the blockchain was created. This ensures consistency between the native token supply and the remote token counterpart._ |
| 49 | + |
| 50 | +```bash |
| 51 | +export NATIVE_TOKEN_REMOTE_L1="Deployed To Address" |
| 52 | +``` |
| 53 | +</Step> |
| 54 | +<Step> |
| 55 | +### Granting Native Minting Rights to NativeTokenRemote Contract |
| 56 | +To ensure that the `NativeTokenRemote` contract can mint native tokens on the L1 when USDC tokens are transferred from the `C-Chain`, the contract must be granted **minting rights**. This is done by adding the `NativeTokenRemote contract` address to the `Native Minter Precompile`. |
| 57 | + |
| 58 | +1. You will need to interact with the `Native Minter Precompile`, which resides at a fixed address on all Avalanche L1s: |
| 59 | +**Native Minter Precompile Address**: `0x0200000000000000000000000000000000000001` |
| 60 | + |
| 61 | +2. Use the following command to grant the `NativeTokenRemote` contract minting rights by setting it as an **enabled** address on the Native Minter Precompile: |
| 62 | + |
| 63 | +```bash |
| 64 | +cast send --rpc-url myblockchain --private-key $PK 0x0200000000000000000000000000000000000001 "setEnabled(address)" $NATIVE_TOKEN_REMOTE_L1 |
| 65 | +``` |
| 66 | + |
| 67 | +- `$NATIVE_TOKEN_REMOTE_L1`: The deployed address of the `NativeTokenRemote` contract on your L1. |
| 68 | + |
| 69 | +Once this step is completed, the `NativeTokenRemote` contract will have the necessary permissions to mint native tokens when USDC tokens are transferred from the C-Chain. |
| 70 | +</Step> |
| 71 | +<Step> |
| 72 | +### Register Remote Token with Home Transferer |
| 73 | +Register the remote token on the home chain so that it recognizes the transferer contracts. |
| 74 | + |
| 75 | +```bash |
| 76 | +cast send --rpc-url myblockchain --private-key $PK $NATIVE_TOKEN_REMOTE_L1 "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" |
| 77 | +``` |
| 78 | +</Step> |
| 79 | +<Step> |
| 80 | +### Collateralize and Transfer Tokens |
| 81 | +Add collateral to the transferer contract on the home chain, and then send the USDC tokens across chains. |
| 82 | + |
| 83 | +<Accordions> |
| 84 | +<Accordion title="What is Collateral?"> |
| 85 | +Collateral in this context refers to the amount of the token that is locked in the `Home Transferer contract` on the source chain (`C-Chain`) to back the value of the token on the destination chain (`myblockchain`). This ensures that for every token minted on the remote chain, there’s an equivalent token locked as collateral on the home chain. |
| 86 | +</Accordion> |
| 87 | +<Accordion title="Why is Collateral Important?"> |
| 88 | +Collateralization ensures that the total supply of the token remains consistent across both chains. When tokens are sent from the `home chain`, they are locked as collateral, and a corresponding number of tokens is minted on the remote chain. If tokens are sent back to the home chain, the collateral is unlocked, and the minted tokens on the remote chain are burned. |
| 89 | +</Accordion> |
| 90 | +</Accordions> |
| 91 | + |
| 92 | +- **Approve Tokens for Transfer** |
| 93 | +Approve a certain number of tokens to be used by the Home Transferer. |
| 94 | + |
| 95 | +```bash |
| 96 | +cast send --rpc-url local-c --private-key $PK $USDC "approve(address, uint256)" $USDC_HOME_C_CHAIN 2000000000000000000000 |
| 97 | +``` |
| 98 | + |
| 99 | +- **Add Collateral and Send Tokens** |
| 100 | +Add collateral to the transferer contract. |
| 101 | +```bash |
| 102 | +cast send --rpc-url local-c --private-key $PK $USDC_HOME_C_CHAIN "addCollateral(bytes32, address, uint256)" $L1_BLOCKCHAIN_ID_HEX $NATIVE_TOKEN_REMOTE_L1 100000000000000000000 |
| 103 | +``` |
| 104 | +You can also confirm whether the Transferer is collateralized now by running the below command: |
| 105 | + |
| 106 | +```bash |
| 107 | +cast call --rpc-url myblockchain $NATIVE_TOKEN_REMOTE_L1 "isCollateralized()(bool)" |
| 108 | +``` |
| 109 | +Send tokens to the L1 |
| 110 | +```bash |
| 111 | +cast send --rpc-url local-c --private-key $PK $USDC_HOME_C_CHAIN "send((bytes32, address, address, address, uint256, uint256, uint256, address), uint256)" "(${L1_BLOCKCHAIN_ID_HEX}, ${NATIVE_TOKEN_REMOTE_L1}, ${FUNDED_ADDRESS}, ${USDC}, 0, 0, 250000, 0x0000000000000000000000000000000000000000)" 1000000000000000000000 |
| 112 | +``` |
| 113 | +</Step> |
| 114 | + |
| 115 | +<Step> |
| 116 | +Check Balance |
| 117 | +```bash |
| 118 | +cast balance --rpc-url myblockchain $FUNDED_ADDRESS |
| 119 | +``` |
| 120 | +</Step> |
| 121 | +</Steps> |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +### Conclusion |
| 126 | + |
| 127 | +Follow the steps above to transfer a USDC token from the C-Chain to your custom Avalanche L1 and use it as the native token. This exercise will demonstrate how Avalanche’s **Interchain Token Transfer (ICTT)** system works, ensuring that tokens are properly locked, transferred, and minted across multiple chains. |
| 128 | + |
| 129 | +For more detailed information, refer to the [official Avalanche ICTT documentation](/course/interchain-token-transfer). |
0 commit comments