On Solana, SPL token transfers require the recipient to have an Associated Token Account (ATA) for that token. Gas Station does not pay for ATA creation unless you use Solana ATA sponsorship. Without sponsorship, you must create the ATA and pay its rent before a transfer can succeed. This quickstart walks you through a server-side script that creates a USDC ATA. A payer wallet pays the one-time SOL rent, and an owner wallet owns the ATA and receives USDC.Documentation Index
Fetch the complete documentation index at: https://developers.circle.com/llms.txt
Use this file to discover all available pages before exploring further.
All transactions in this guide take place on Solana Devnet. No real funds are
required beyond testnet SOL for rent and fees. You can adapt the code for
mainnet by setting
CLUSTER to 'mainnet-beta' and using mainnet USDC mint
addresses.Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js v18+.
- Created a payer wallet and obtained its keypair (private key).
- Funded the payer wallet with at least ~0.00204 SOL on Solana Devnet to cover
ATA rent-exempt minimum and transaction fees:
- Use the Solana faucet to obtain testnet SOL.
- Obtained the owner wallet’s public key (base58 address). The owner can be a wallet you create or any recipient’s address.
Step 1: Set up the project
This step sets up your project environment and installs the required dependencies.1.1. Create a new project
Create a new directory and initialize a new Node.js project with default settings:Shell
1.2. Install dependencies
Install the required dependencies for Solana and SPL token interactions, and set the start script to run the TypeScript file withtsx:
Shell
1.3. Configure TypeScript (optional)
Create atsconfig.json file:
tsconfig.json file:
1.4. Configure environment variables
Create a.env file with PAYER_PRIVATE_KEY (payer keypair as a JSON array)
and OWNER_PUBLIC_KEY (base58 address of the wallet that will own the ATA):
Shell
PAYER_PRIVATE_KEY should be a JSON array of bytes representing your
private key. You can export this from most Solana wallets.
Converting Base58 private key to JSON array
Converting Base58 private key to JSON array
Some wallets export Solana private keys as Base58 encoded strings. If you have a
Base58 encoded private key, install
bs58, save the following code as
convert-key.ts, and run it with tsx to convert it to a JSON array:Shell
TypeScript
Step 2: Create the script
This step creates the complete script. It adds imports and configuration, implements ATA creation, and runs the script.2.1. Import dependencies
Create anindex.ts file:
Shell
index.ts
2.2. Add the ATA creation logic
Add the following code toindex.ts. This code defines the createUSDCata
function and the main function.
How this script works
How this script works
The
createUSDCata function:- Derives the ATA address.
- Builds the idempotent ATA instruction.
- Sends the transaction.
main function:- Loads the payer keypair and owner address from
.env. - Initializes the Solana connection.
- Calls
createUSDCata. - Prints the final ATA address.
index.ts
2.3. Run the script
Run the script with the following command:Shell