Overview
Sending USDC, or other ERC-20 tokens, is one of the most common actions taken by wallet users on Ethereum-based chains. This guide will walk you through how to send USDC using Dynamic’s embedded wallets.Step 1: Get the USDC Contract Address
To send USDC, you’ll need the contract address for USDC. The address is different for each network, so make sure you get the correct address for the network you’re targeting. You can go to Circle’s website to look up the USDC address on both main networks and test networks.Step 2: Format the Transaction Data
USDC, and other ERC-20 tokens, are smart contracts. In order to send these tokens, your transaction needs to call thetransfer
function on the contract, which takes in two parameters:
to
: The address of the recipientvalue
: The amount of tokens to send
viem
to provide the ABI and encode the function parameters.
Additionally, each ERC-20 token defines a decimals
value, which is the number of decimal places for the token. For USDC, the decimals
value is 6.
First, ensure you have the required dependencies installed for your platform:
Step 3: Send the Transaction
You can send the transaction using Dynamic’s wallet APIs. Below are examples for React, React Native, and Swift.Important Considerations
Gas Fees
- EVM Networks: Gas fees are paid in the native token (ETH, MATIC, etc.)
- Gasless Transactions: Some networks support gasless USDC transfers using account abstraction in React and React Native.
USDC Decimals
- EVM USDC: 6 decimal places
- Always use
parseUnits(amount, 6)
when converting amounts
Error Handling
Always implement proper error handling for failed transactions:Best Practices
- Always validate addresses before sending transactions
- Check USDC balance before attempting transfers
- Implement proper error handling and user feedback
- Test on testnets before deploying to mainnet
- Consider gas fees when calculating transfer amounts
- Use transaction simulation to show users exactly what will happen