@stellar/stellar-sdk to:
- Create and fund a Stellar Testnet wallet
- Establish a USDC trustline so the wallet can receive USDC
This quickstart funds the account with Friendbot’s HTTP API from your script.
You can use Stellar Lab to fund on
Stellar Testnet in the browser.
Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js v22.6+ or later
- Set up a terminal and code editor for running commands and editing files
Step 1. Set up the project
This step shows you how to prepare your project and environment.1.1. Create the project and install dependencies
Create a new directory and install the required dependencies:Shell
1.2. Configure TypeScript (optional)
Create atsconfig.json file:
tsconfig.json file:
Step 2: Create the trustline script
Addmain.ts at the project root. The script generates a keypair, requests test
XLM from Friendbot (Stellar’s faucet), submits a changeTrust for testnet USDC,
and posts the transaction to
Horizon (Stellar’s HTTP
API for submitting transactions).
main.ts
Common errors you might encounter:
Friendbot funding failed: 400— The Friendbot rate limit was exceeded. Wait a few seconds and try again.Transaction failed— The account may not be funded, or the USDC issuer address may be incorrect. Verify theUSDC_ISSUERconstant matches the Stellar Testnet USDC issuer.
Step 3: Run the script
From the project directory, run:Shell
Shell