Prerequisites
Before you start building the sample app to perform a EURC transfer, make sure you have:- Installed Node.js and npm. You can download and install Node.js directly, or use a version manager like nvm. The npm binary comes with Node.js.
- Installed MetaMask. You can download and install MetaMask from their website. When performing initial setup, you should create a wallet for the Ethereum Sepolia testnet.
- Testnet native tokens and testnet EURC in your wallet. You can get Sepolia ETH (native token) from a public faucet and you can get Sepolia EURC 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 Node.js project:
Shell
- Install the required dependencies in your project directory:
Shell
- Install the viem library:
Shell
Build 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.Set up public client
The public client is used to read blockchain data, such as transaction receipts or token balances. Configure the client to connect to the Sepolia testnet:Typescript
Set up wallet client
The wallet client lets you interact with user accounts and sign transactions. To connect it to MetaMask in the browser:Typescript
Define EURC contract details
Define the EURC contract address and the application binary interface (ABI). The ABI specifies the functions available on the smart contract. Note that the EURC token contract address varies by blockchain. This example uses the Ethereum Sepolia contract address. For the full list of EURC smart contract addresses, see EURC Contract Addresses.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 EURC 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 EURC transaction, create anindex.tsx and index.html file in your project
directory and populate them with the sample code below. The resulting app
enables you to send EURC tokens from one wallet to another. The source wallet
must contain native testnet tokens (to pay for gas fees) and testnet EURC.
index.tsx
Typescript
index.html
HTML
Screenshots
Wallet connect screen:
