App examples
USDC bridging
This solutions guide explains how to bridge USDC (USD Coin) between Base and Arbitrum networks using the CDP SDK and Circle’s Cross-Chain Transfer Protocol (CCTP).
Prerequisites
Before you begin, make sure you have the following:
- Installed the CDP SDK.
- A CDP Secret API Key (configured in a JSON file).
- Node.js and npm installed on your system.
- Have a persisted funded API Wallet on the Base network (minimum of 0.005 Base mainnet ETH and some amount of USDC) and another on Arbitrum (minimum of 0.005 Arbitrum mainnet ETH). See creating a wallet to quickly spin up a 1-of-1 Developer-Managed wallet, and refer to persisting a wallet for more information on how to save it.
Step-by-Step Guide
Step 1: Set Up the Project
First, let’s set up our project, import the necessary dependencies, and declare the required variables including contract ABIs:
usdc-bridging.ts
Step 3: Create Bridging Function and Helper Functions
Using existing Base and Arbitrum mainnet wallets, we’ll create a function to bridge USDC between the two networks.
usdc-bridging.ts
Step 4: Create the Main Function
Finally, let’s create the main function to orchestrate the entire process:
This sample app is for demonstration purposes only. Make sure to secure your wallets and only use small amounts of USDC for testing to minimize risks.
Helpful Tips
- Gas Fees: Ensure you have enough ETH on both Base and Arbitrum networks to cover gas fees for the transactions.
- USDC Decimals: Remember that USDC uses 6 decimal places. When specifying amounts, multiply by 10^6 (e.g., 1 USDC = 1000000).
- Contract Addresses: The contract addresses used in this guide are for mainnet. For testnet development, use the appropriate testnet contract addresses.
- Error Handling: In a production environment, add more robust error handling and logging to manage potential issues during the bridging process.
- Wallet Security: Be cautious with wallet seeds and private keys. Never expose them in your code or commit them to version control.
- Rate Limiting: Be aware of rate limits when calling the Circle API for attestations. Implement appropriate waiting mechanisms if necessary.
- Testing: Always test your bridging process with small amounts before moving larger sums.
- Additional Networks: This guide uses Base and Arbitrum networks. You can use other networks supported by CCTP by modifying the code.