Prerequisites
Before you start, ensure you have:- Installed Node.js v22+
- Created a TypeScript project and installed the
viempackage. - Created a wallet with the private key available on the source chain.
- Funded the wallet with testnet USDC and native tokens for gas fees on the source chain.
- Created a
.envfile with your private key and recipient address.
Steps
Use the following steps to transfer USDC with the Forwarding Service.Step 1. Get CCTP fees from the API
Query the CCTP API for the fees for transferring USDC from Base Sepolia to Avalanche Fuji. This value is passed to themaxFee parameter in the
depositForBurnWithHook transaction. The following is an example request using
source domain 6 (Base Sepolia) and destination domain 1 (Avalanche Fuji):
forwardFee is the fee charged by the Forwarding Service. The minimumFee
is the CCTP protocol fee (a flat fee in cents of USDC).
Step 2. Calculate the USDC amounts and fees
Calculate the total fee by combining the protocol fee and the Forwarding Service fee. ThemaxFee parameter must cover both fees for the transfer to succeed.
Step 3. Approve the USDC transfer
Grant approval for theTokenMessengerV2 contract deployed on
Base to transfer USDC from your wallet. Approve at least totalAmount
(including fees) calculated in Step 2.
Step 4. Sign and broadcast a depositForBurnWithHook transaction on the TokenMessengerV2 contract
Create and send a depositForBurnWithHook transaction with the Forwarding
Service hook data. The hook data tells the CCTP Forwarding Service to
automatically forward the mint transaction on the destination chain.
The Forwarding Service hook data is a static 32-byte value containing the magic
bytes cctp-forward, version 0, and length 0. For details on the hook
format, see
Forwarding Service hook format.
depositForBurnWithHook transaction:
Use
totalAmount (transfer amount + fees) for the amount parameter. The
recipient receives only the transfer amount after fees are deducted.mintRecipient address on the destination chain.
The recipient receives transferAmount USDC (fees are automatically deducted
from the burned amount).
Step 5. Verify the mint transaction
After the burn transaction is confirmed, query the Circle Iris API to retrieve the forwarding details. The API returns theforwardTxHash, which is the mint
transaction hash on the destination chain.
The attestation may take time to become available, depending on the destination
chain. Poll the API until the message is ready:
Full example code
The following is a complete example of how to transfer USDC from Base Sepolia to Avalanche Fuji using the Forwarding Service. Remember to set thePRIVATE_KEY
and DESTINATION_ADDRESS environment variables.