Skip to main content
This quickstart guide helps you write a standalone index.js script that checks your USDC balance and sends a test transfer on the Sei Atlantic-2 Testnet. It’s designed for developers looking to quickly get hands-on with USDC on Sei.

Prerequisites

Before you begin, make sure you have:

USDC contract address

Use the following contract address for USDC on the Sei Atlantic-2 Testnet:

Part 1: Set up your project

Follow these steps to install dependencies and set up your script environment.

1. Initialize a project

Create a new directory and initialize it with npm:
Shell

2. Install required dependencies

Install viem and dotenv:
Shell

3. Create your .env file

In the project root, create a .env file and add the following values:
Your private key must be a 0x-prefixed 64-character hex string.

Part 2: Build your script

Create a file named index.js. You’ll build your script step-by-step in the following sections.

1. Import libraries and define constants

In index.js, start by importing dependencies and setting up the chain and token configuration:
Typescript
This ABI includes only the two methods needed for this script:
  • balanceOf(address) to check the token balance.
  • transfer(to, amount) to send USDC.
This makes the ABI compact and easier to understand. Using a minimal ABI:
  • Reduces complexity by excluding unrelated functions.
  • Speeds up onboarding for new developers.
  • Avoids unnecessary contract data that would be unused in this context.

2. Load environment variables and validate inputs

Next, load your credentials from .env and validate them:
Typescript
Failing fast means catching mistakes early in the execution cycle. This script validates inputs to avoid:
  • Missing or undefined environment variables.
  • Private keys that are not prefixed with 0x.
  • Recipient addresses that don’t follow Ethereum address formatting.
These checks:
  • Prevent runtime failures deeper in the logic.
  • Help you debug configuration issues immediately.
  • Save time and reduce the risk of sending faulty transactions.

3. Set up Viem clients

Set up the Viem clients and your account object:
Typescript
  • publicClient calls eth_call to read blockchain data. It doesn’t need your private key.
    • Use this for functions like balanceOf, symbol, or decimals.
  • walletClient sends transactions using eth_sendTransaction.
    • It signs data with your private key and requires a funded account.
Both clients use the same RPC connection but serve different roles.

4. Check balance and send USDC

Now add the logic to check your balance and send tokens:
Typescript
Token contracts use the smallest indivisible unit of a token. For USDC, that’s 6 decimal places.
  • formatUnits(value, 6) converts raw blockchain balances into readable amounts like 250.0.
  • parseUnits('10', 6) converts user inputs into raw values like 10000000 (10 * 10^6).
These utilities:
  • Prevent incorrect math during transfer.
  • Ensure compatibility with ERC-20 functions.
  • Improve display formatting in logs and UI.

Part 3: Run your script

To run your script, use the following command:
Shell

Sample output

If the script runs successfully, your terminal will print a transaction summary like this:
You can open the explorer link in your browser to view the transaction on SeiTrace.

Additional notes

  • Testnet only: This guide runs on the Sei testnet. Tokens and transfers here are not real and hold no value.
  • Security best practices: Always store sensitive data like private keys in environment variables. Never hardcode or commit .env files to version control.
  • Gas fees: All EVM-compatible chains require gas. Be sure to request testnet SEI from the faucet so your transactions can be mined.
  • Lightweight ABI: The ABI used here is minimal. It includes only the functions necessary for balance checks and transfers, which keeps the script lean.
  • Auto-prefixing: Some tools or environments strip the 0x prefix from private keys. This script adds it back if needed to avoid errors.