Skip to main content
USDC on Stellar is a native asset issued by Circle. Transferring USDC between Stellar accounts uses a standard payment operation, submitted through Horizon, Stellar’s HTTP API for submitting transactions. To transfer USDC crosschain between Stellar and other blockchains, see Transfer USDC to and from Stellar. The @stellar/stellar-sdk script you build in this guide will:
  • Create and fund a recipient Stellar Testnet wallet
  • Establish a USDC trustline on the recipient account
  • Transfer USDC from your existing sender wallet to the recipient
Before a Stellar account can receive USDC, it must establish a trustline for the asset. See Set up a USDC trustline on Stellar for more detail. This quickstart handles trustline setup automatically as part of the script.

Prerequisites

Before you begin, ensure that you have:
  • Installed Node.js v22.6+
  • Set up a terminal and code editor for running commands and editing files
  • Created a Stellar Testnet wallet with the secret key (S...) available

Contract addresses

You need the following Stellar Testnet USDC issuer address:

Step 1: Set up the project

1.1. Create the project and install dependencies

Create a new directory and install the required dependencies:
Shell

1.2. Configure TypeScript (optional)

This step is optional. It helps prevent missing types in your IDE or editor.
Create a tsconfig.json file:
Then, update the tsconfig.json file:

1.3. Configure environment variables

Create a .env file in your project directory and add your sender’s secret key:
.env
Open .env in your editor rather than writing values with shell commands, and add .env to your .gitignore. This prevents credentials from leaking into your shell history or version control.
This example uses one or more private keys for local testing. In production, use a secure key management solution and never expose or share private keys.

Step 2: Create the transfer script

Add main.ts at the project root. The script:
  1. Loads your existing sender wallet from the environment variable
  2. Creates and funds a new recipient wallet using Friendbot
  3. Establishes a USDC trustline on the recipient account
  4. Submits a USDC payment from the sender to the recipient
main.ts

Step 3: Run the script

From the project directory, run:
Shell
Your output should look similar to the following (addresses and hashes will differ):
Shell
Common errors you might encounter:
  • Friendbot funding failed: 400 — The Friendbot rate limit was exceeded. Wait a few seconds and try again.
  • op_no_trust — The recipient account does not have a USDC trustline. The script establishes one automatically, but if you’re adapting this example for your own recipient address, ensure the trustline exists first. See Set up a USDC trustline on Stellar.
  • op_underfunded — The sender does not have enough USDC. Ensure your sender wallet is funded with testnet USDC from the Circle Faucet before running the script.
For more detail on Stellar-specific USDC behavior in CCTP, including address encoding and decimal precision, see CCTP on Stellar.