Prerequisites
Before you start building the sample app to perform a USDC transfer, ensure you meet the following prerequisites:- Node.js and npm are installed. You can download and install Node.js directly, or use a version manager like nvm. The npm binary comes with Node.js.
- MetaMask is installed. You can download and install MetaMask from their website. When performing initial setup, you should create a wallet for the Ethereum Sepolia testnet.
- You have testnet native tokens and testnet USDC in your wallet. You can get Sepolia ETH (native token) from a public faucet and you can get Sepolia USDC from the Circle Faucet.
Project setup
To begin building the sample app, first set up your project environment and install dependencies. Create a new project directory and initialize a project in it:Shell
Shell
Shell
Building the transfer app
The following sections outline the relevant business logic of the example app. You can view the full source for the app in the final section of this guide.Set up public client
The public client interacts with the blockchain network. In this example, you should specify the Ethereum Sepolia network.Typescript
Set up wallet client
The wallet client interacts with Ethereum accounts to retrieve balances, execute transactions, and sign messages.Typescript
Define USDC contract details
Define the USDC contract address and the application binary interface (ABI). The ABI specifies the functions available on the smart contract. Note that the USDC token contract address varies by blockchain. This example uses the Ethereum Sepolia contract address. See USDC Contract Addresses for a full list of addresses for the USDC smart contract.Typescript
Connect wallet
Create a function to connect to the user’s wallet in MetaMask and retrieve the wallet address.Typescript
Send transaction
Create a function to send the USDC transfer transaction. This function encodes the transfer function data and sends the transaction to the blockchain using the wallet client.Typescript
Wait for transaction receipt
Use the public client to wait for the transaction receipt, which confirms that the transaction was included in a block.Typescript
Full source
Now that you understand the core steps for programmatically performing a USDC transaction, create anindex.tsx and index.html file in your project
directory and populate them with the sample code below. This app enables you to
send USDC tokens from one wallet to another. The source wallet must contain
native testnet tokens (to pay for gas fees) and testnet USDC.
index.tsx
Typescript
index.html
HTML
Screenshots
Wallet connect screen:
