@aptos-labs/ts-sdk script you
build in this guide will:
- Load your sender wallet from a private key
- Check your testnet USDC balance
- Transfer USDC to a recipient address you set in the script
Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js v22.6+
- Set up a terminal and code editor for running commands and editing files
- Created an Aptos Testnet wallet with the private key available
- Funded with testnet APT (for transaction fees) from the Aptos Faucet
- Funded with testnet USDC from the Circle Faucet
Contract addresses
You need the following Aptos Testnet USDC fungible asset metadata address:Step 1: Set up the project
1.1. Create the project and install dependencies
Create a new directory, setup a Node.js project, and install the required dependencies:Shell
1.2. Configure TypeScript (optional)
Create atsconfig.json file:
tsconfig.json file:
1.3. Configure environment variables
Create a.env file in your project directory and add your sender’s private
key. Use either an AIP-80 formatted key (ed25519-priv-0x...) or a raw hex
private key from your wallet export.
.env
Step 2: Create the transfer script
Addmain.ts at the project root. The script:
- Loads your existing sender wallet from the environment variable
- Reads the sender’s USDC balance
- Builds a fungible asset transfer to your recipient address
- Signs, submits, and waits for the transaction
0xYOUR_RECIPIENT_ADDRESS with the Aptos address that should receive
the USDC.
main.ts
Step 3: Run the script
From the project directory, run:Shell
Shell
Transfer confirmed: line to view the
transaction on Aptos Testnet.
Common errors you might encounter:
Set APTOS_PRIVATE_KEY in .env: The private key is missing. AddAPTOS_PRIVATE_KEYto.envand run withnpm run start(which loads the file via--env-file).Insufficient USDC: The sender does not have enough testnet USDC. Fund the wallet from the Circle Faucet before running the script.- Transaction failure / out of gas: The sender needs testnet APT for fees. Request APT from the Aptos Faucet.