Prerequisites
Before you start building the sample app to perform a USDC transfer, ensure you have:- Node.js and npm installed on your development machine. You can download and install Node.js directly, or use a version manager like nvm. The npm binary comes with Node.js.
- Created an Ethereum wallet and have the private key available.
- Funded your wallet with the following testnet tokens:
- Sepolia ETH (native token) from a public faucet.
- Sepolia USDC from the Circle Faucet.
- Arc testnet USDC (for gas fees) from the Circle Faucet.
Part 1: Project setup
Set up your project environment and install the required dependencies.1.1. Create a new project
Create a new directory and initialize a newNode.js project with default
settings:
Shell
package.json file.
1.2. Install dependencies
In your project directory, install the required dependencies, includingviem:
Shell
package.json file with the
dependencies.
1.3. Add module type
Use the npmpkg command to set the module type to module:
Shell
1.4. Configure environment variables
Create a.env file in your project directory and add your wallet private key:
Shell
Part 2: Configure the script
This section covers the necessary setup for the transfer script, including defining keys and addresses, and configuring the wallet client for interacting with the source and destination chains.2.1. Define configuration constants
The script predefines the contract addresses, transfer amount, and maximum fee. Update theDESTINATION_ADDRESS with your wallet address.
JavaScript
2.2. Set up wallet clients
The wallet client configures the appropriate network settings usingviem. In
this example, the script connects to Ethereum Sepolia and Arc testnet.
JavaScript
Part 3: Implement the transfer logic
The following sections outline the core transfer logic.3.1. Approve USDC
Grant approval for theTokenMessengerV2 contract deployed on
Ethereum Sepolia to withdraw USDC from your wallet. This allows the contract to
burn USDC when you initiate the transfer.
JavaScript
3.2. Burn USDC
Call thedepositForBurn function from the
TokenMessengerV2 contract
deployed on Ethereum Sepolia to burn USDC on that source chain. You specify the
following parameters:
- Burn amount: The amount of USDC to burn
- Destination domain: The target blockchain for minting USDC (see supported chains and domains)
- Mint recipient: The wallet address that will receive the minted USDC
- Burn token: The contract address of the USDC token being burned on the source chain
- Destination caller: The address on the target chain to call
receiveMessage - Max fee: The maximum fee allowed for the transfer
- Finality threshold: Determines whether it’s a Fast Transfer (1000 or less) or a Standard Transfer (2000 or more)
JavaScript
3.3. Retrieve attestation
Retrieve the attestation required to complete the CCTP transfer by calling Circle’s attestation API.- Call Circle’s
GET /v2/messagesAPI endpoint to retrieve the attestation. - Pass the
srcDomainargument from the CCTP domain for your source chain. - Pass
transactionHashfrom the value returned bysendTransactionwithin theburnUSDCfunction above.
JavaScript
3.4. Mint USDC
Call thereceiveMessage function
from the MessageTransmitterV2 contract
deployed on the Arc testnet to mint USDC on that destination chain.
- Pass the signed attestation and the message data as parameters.
- The function processes the attestation and mints USDC to the specified Arc testnet wallet address.
JavaScript
Part 4: Complete script
Create atransfer.js file in your project directory and populate it with the
complete code below.
transfer.js
Part 5: Test the script
Run the following command to execute the script:Shell
Rate limit:The attestation service rate limit is 35 requests per second. If you exceed this
limit, the service blocks all API requests for the next 5 minutes and returns an
HTTP 429 (Too Many Requests) response.