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 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:

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 with npm:

1.2. Install required dependencies

Install starknet (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 named index.js. You’ll build your script step-by-step in the following sections.

2.1. Import libraries and define constants

In index.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/starknet
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.
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:
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.
This enables features like:
  • 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
You can open the explorer link in your browser to view the transaction on Voyager.

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 .env files to version control. Add .env to your .gitignore file.
  • 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.