index.js script that checks
your USDC balance and sends a test transfer on the Starknet Sepolia. It’s
designed for developers looking to quickly get hands-on with
USDC on Starknet.
Prerequisites
Before you begin, make sure you have:- Installed Node.js v18+ and
npm, which comes withNode.js.- Created a free Alchemy account to get an API key for Starknet RPC access.
- Created a Starknet Sepolia wallet:
- Braavos wallet (Recommended) - Best compatibility for programmatic transactions. Alternatives: Argent X (Note: Guardian-protected accounts may require additional configuration).
- Request testnet STRK from the faucet.
- Request testnet USDC from the faucet
USDC contract address
Use the following contract address for USDC on the Starknet Sepolia Testnet: USDC contract:0x0512feAc6339Ff7889822cb5aA2a86C848e9D392bB0E3E237C008674feeD8343
Part 1: Set up your project
Follow these steps to install dependencies and set up your script environment.1.1. Initialize a project
Create a new directory and initialize it withnpm:
1.2. Install required dependencies
Installstarknet (version 8.x) and dotenv:
1.3. Create your .env file
In the project root, create a .env file and add the following values:
Text
Important: On Starknet, you need both your account address and private key
because Starknet uses account
abstraction. Your private
key alone doesn’t derive your account address.
Part 2: Build your script
Create a file namedindex.js. You’ll build your script step-by-step in the
following sections.
2.1. Import libraries and define constants
Inindex.js, start by importing dependencies and setting up the chain and
token configuration:
Replace
YOUR_API_KEY with your Alchemy API key from
alchemy.com/starknetLearn more: Why use a minimal ABI?
Learn more: Why use a minimal ABI?
This ABI includes only the two methods needed for this script:
balanceOf(address)to check the token balance.transfer(to, amount)to send USDC.
- Reduces complexity by excluding unrelated functions.
- Speeds up onboarding for new developers.
- Avoids unnecessary contract data that would be unused in this context.
Note: Starknet uses Cairo, so function names follow snake_case convention
(for example,
balance_of instead of balanceOf).2.2. Set up Starknet account and contract
Set up the Starknet account and contract instances:Learn more: account abstraction on Starknet
Learn more: account abstraction on Starknet
Unlike Ethereum, Starknet uses account abstraction by default:
- Every wallet is a smart contract (not an EOA).
- You need both the account address AND private key.
- The private key signs transactions, but the account contract validates them.
- Multi-signature wallets
- Social recovery
- Custom transaction validation logic
- Gasless transactions (meta-transactions)
2.3. Check balance and send USDC
Now add the logic to check your balance and send tokens:Part 3: Run your script
To run your script, use the following command:Sample output
If the script runs successfully, your terminal will print a transaction summary like this:Text
Additional notes
- Testnet only: This guide runs on the Starknet Sepolia 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
.envfiles to version control. Add.envto your.gitignorefile. - Gas fees: Starknet requires STRK tokens for gas. Be sure to request testnet STRK from the faucet so your transactions can be processed.
- Lightweight ABI: The ABI used here is minimal. It includes only the functions necessary for balance checks and transfers, which keeps the script lean.
- V3 transactions: Starknet.js v8 uses V3 transactions by default, which include resource bounds for L1 gas, L2 gas, and L1 data gas.
- Wallet compatibility: Braavos wallet is recommended for programmatic transactions. Argent accounts with guardians may require additional configuration.