Prerequisites
Before you begin, make sure you have:- Installed Node.js v18+.
- Prepared a HyperEVM testnet wallet funded with:
- Testnet USDC for the transfer.
- Testnet HYPE for gas fees.
- A private key and a recipient address stored in a
.envfile.
To get HyperEVM testnet USDC
Use Circle’s faucet or transfer USDC from another chain using the CCTP sample app.
Use Circle’s faucet or transfer USDC from another chain using the CCTP sample app.
Step 1: Set up your project
-
Initialize a new Node.js project and install dependencies:
Shell
-
In the project root, create a
.envfile with your private key and recipient address:Shell -
Create an
index.jsfile. You’ll add code step by step in the following sections.
Step 2: Configure chain and contract
Inindex.js, import required modules and define constants for the HyperEVM
testnet and the USDC contract:
Javascript
Learn more: Chain and contract configuration
Learn more: Chain and contract configuration
- Imports required modules from Viem and your
.envfile. - Loads the HyperEVM testnet configuration.
- Defines the USDC contract address, decimals, and minimal ABI.
- Only includes the
balanceOfandtransferfunctions, since they’re all that’s needed for this guide.
Step 3: Load environment variables
Next, load your private key and recipient address from.env:
Javascript
Learn more: Environment variables
Learn more: Environment variables
- Loads values from the
.envfile so you don’t hardcode sensitive information. - Checks that both the private key and recipient address are set.
- Validates the recipient address format with a regex.
- Ensures the private key is properly prefixed with
0xso Viem can use it.
Step 4: Initialize Viem clients
Create a public client for reading blockchain data and a wallet client for sending transactions:Javascript
Learn more: Viem clients
Learn more: Viem clients
privateKeyToAccountcreates an account object from your private key.createPublicClientis used for reading data from the blockchain (no private key needed).createWalletClientuses your account to sign and send transactions.- Together, these clients give you read and write access to HyperEVM.
Step 5: Transfer USDC
Now, write the main logic to check your balance and send a transfer:Javascript
Learn more: Transfer logic
Learn more: Transfer logic
- Reads your USDC balance using the
balanceOffunction. - Converts the balance into a human-readable format with
formatUnits. - Sets the transfer amount (1 USDC in this example).
- Validates that your balance is sufficient.
- Converts the transfer amount back into smallest units with
parseUnits. - Calls the
transferfunction on the USDC contract to send tokens. - Logs the transaction hash and a block explorer link so you can verify the transfer.
Step 6: Run the script
After running the script:Shell
Explorer: line
and open it in your browser. This will take you to the HyperEVM testnet
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 HyperEVM testnet explorer.
Summary
In this quickstart, you learned how to check balances and transfer USDC on HyperEVM using Viem and Node.js. Here are the key points to remember:- Testnet only. HyperEVM testnet USDC has no real value.
- Gas fees. You need a small amount of testnet HYPE for gas.
- Security. Keep your private key in
.env. Never commit secrets. - Minimal ABI. The script only uses
balanceOfandtransferfor simplicity.