Prerequisites
Before you begin, make sure you have:- Installed Node.js and
npm. You can download and install
Node.jsfrom Nodejs.org.npmcomes withNode.js. - Installed Metamask
- Some Sonic testnet tokens in your wallet to cover transaction fees. You can use the Sonic Faucet.
- Testnet USDC tokens in your wallet for the transfer. You can use the CCTP Sample App to move testnet USDC from Ethereum Sepolia to Sonic Blaze.
Contract address
You will need the following contract address for the USDC token on Sonic Blaze Testnet:- USDC contract -
0xA4879Fed32Ecbef99399e5cbC247E533421C4eC6
Part 1: Set up your project
Perform the following installation and setup steps:- Create a new project directory and initialize it with
npm:
Shell
- Install the required dependencies:
Shell
- Verify the installation by checking the
package.jsonfile. It should look like this:
JSON
package.json file does not contain the scripts section, copy and paste
it from the above code into your file. Test that you can run the project with
the command:
Shell
Part 2: Import clients and set up helpers
Perform the following steps to import code and set up helpers for the application.- Create a new file
src/client.tsand copy the following code into it. This code imports required libraries and sets up the network configuration.
Typescript
- Define the USDC testnet token contract details in a new file
src/constants.ts. This file contains the contract address and Application Binary Interface (ABI) for the USDC token on Sonic Blaze.
Typescript
Part 3: Create the main application component
The following steps create the main application component and show the steps to connect a wallet and transfer USDC.- Create a new file
src/App.tsxand copy the following code into it. This code contains the main application component that allows users to connect their wallet and transfer USDC.
Typescript
- Create your application entrypoint by creating a new file
src/main.tsxand copying the following code into it. This code sets up the React application and renders theUSDCAppcomponent.
Typescript
- Create a new file
index.htmlin the root directory and copy the following code into it. This code sets up the HTML structure for the application.
HTML
- Run your application using the following command:
Shell
Connecting your wallet
- In the application, click the Connect Wallet button. This will prompt you to connect your wallet using Metamask.
- Select your Sonic wallet address from the available options.
- Approve the connection request in Metamask.
Transferring USDC
- In the app, enter the amount of USDC to send, and the recipient’s wallet address.
- Click Send Tokens
- Review the transaction details in the Metamask pop-up and approve the transaction.
- Wait for the transaction to be confirmed. The app displays the transaction hash and status once the transfer is complete.
- You can check the transaction status on the Sonic Explorer.