Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js and npm on your development machine
- Created a testnet wallet on Ethereum Sepolia, Base Sepolia, and Avalanche Fuji and have the private key available
- Funded your testnet wallet with native tokens on the destination chain (Avalanche Fuji)
- Deposited 10 USDC into the Gateway Wallet contracts on Ethereum Sepolia and Base Sepolia (creating a unified balance of 20 USDC)
-
Created a new Node project and have the following dependencies installed:
viemdotenv
-
Set up a
.envfile with the following variables:
Steps
Follow these steps to transfer a unified USDC balance. This example uses a unified balance split between Ethereum Sepolia and Base Sepolia. You can adapt it for any chains where you hold a unified balance.Step 1. Create burn intents for the source chains
Create a new file calledindex.js in the root of your project and add the
following code to it. This code creates
burn intents for 5 USDC on
Ethereum Sepolia and 5 USDC on Base Sepolia.
Javascript
Note: For production apps, verifying the balance on each chain before
creating burn intents is best practice. For this how-to, it’s assumed that the
balances are created per the prerequisites. For a complete
end-to-end example that includes checking and error handling, see the
Gateway Quickstart.
Step 2. Sign the burn intents
Add the following code toindex.js. This code constructs the signed burn
intents for submission to the Gateway API.
Note: The additional imports should be added at the top of the file.
Javascript
Step 3. Submit the burn intents to the Gateway API to obtain an attestation
Add the following code toindex.js. This code constructs a Gateway API request
to the /transfer endpoint and obtains the attestation from that endpoint.
Javascript
Step 4. Transfer USDC to the destination chain
Add the following code toindex.js. This code performs a call to the Gateway
Minter contract on Avalanche to instantly mint the USDC to your account on that
chain.
Note: The additional imports should be added at the top of the file.
Javascript
Step 3. Run the script
Once you have added the code to yourindex.js file, run it with the following
command:
Shell