Skip to main content
This guide walks you through transferring USDC on EVM testnets using Viem and Node.js. You’ll build a simple script that checks your balance and sends test transfers.

Prerequisites

Before you begin, ensure that you’ve:
  • Installed Node.js v22.6+
  • Prepared a testnet wallet on the selected chain funded with:
    • Testnet USDC for the transfer
    • Testnet native tokens for gas fees
You can get testnet USDC from Circle’s faucet.

Step 1. Set up the project

This step shows you how to prepare your project and environment.

1.1. Create the project and install dependencies

Create a new directory and install the required dependencies:
Shell

1.2. Configure TypeScript (optional)

This step is optional. It helps prevent missing types in your IDE or editor.
Create a tsconfig.json file:
Then, update the tsconfig.json file:

1.3. Set environment variables

Create a .env file in the project directory and add your wallet private key, replacing {YOUR_PRIVATE_KEY} with the private key from your EVM wallet and {YOUR_RECIPIENT_ADDRESS} with the address of the recipient.
  • PRIVATE_KEY is the private key for the EVM wallet sending the transfer.
  • RECIPIENT_ADDRESS is the EVM wallet address that will receive the USDC.
Open .env in your editor rather than writing values with shell commands, and add .env to your .gitignore. This prevents credentials from leaking into your shell history or version control.
The npm run start command loads variables from .env using Node.js native env-file support.
This example uses one or more private keys for local testing. In production, use a secure key management solution and never expose or share private keys.

Step 2. Create the transfer script

In this step, you’ll build a script in TypeScript that transfers USDC on the selected EVM testnet. The script derives supported chains from Viem, prompts you to choose one at runtime, and then runs the same transfer flow for that chain.

2.1. Create the script file

2.2. Add the script

In index.ts, add the following script. It derives supported chains from the USDC token definition and chain definitions in Viem, so the transfer flow stays shared across EVM testnets. The script uses the client-attached ERC-20 token actions and the USDC token definition from viem/tokens.
TypeScript

Step 3. Run the script

Run the script using the following command:
Shell
You’ll see output similar to the following:
To verify the transfer, copy the transaction hash URL from the Explorer: line and open it in your browser. This will take you to the testnet’s block explorer, where you can view full transaction details.
Tip: If your script doesn’t output a full explorer URL, you can manually paste the transaction hash into the testnet’s block explorer.

Summary

In this quickstart, you learned how to check balances and transfer USDC on EVM testnets using one multichain Viem script in Node.js. Here are the key points to remember:
  • Testnet only. Testnet USDC has no real value.
  • Gas fees. You need a small amount of the testnet’s native token for gas.
  • Security. Keep your private key in .env. Never commit secrets.
  • Single script. The same script works across all supported EVM testnets.
  • Token actions. The script uses ERC-20 token actions and the USDC token definition from viem/tokens instead of a hand-written ABI.