Skip to main content
EURC provides the ability to transfer digital euros over public blockchains using smart contracts. The smart contract lets you send, receive, and store digital euros onchain with a wallet. This guide demonstrates how to use the viem framework to build a simple app that lets a user connect their wallet and interact with the blockchain by sending a EURC transaction from their wallet address.

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:
  1. Create a new project directory and initialize a Node.js project:
Shell
  1. Install the required dependencies in your project directory:
Shell
This sets up your development environment with the necessary libraries and tools for building a React app with TypeScript and Vite.
  1. 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 an index.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
These two source files provide a complete demonstration app that you can use to perform a EURC transfer from a MetaMask wallet. When you open the app, you can connect your wallet, input the recipient address, and click Send to execute the transaction on Ethereum Sepolia. The app provides a transaction receipt once the transaction is included in a block.

Screenshots

Wallet connect screen:
Transfer screen: