Skip to main content
Send USDC stablecoin to another wallet. This automatically creates the recipient’s token account if needed.
import { useSolana } from "@phantom/react-sdk";
import { Connection, PublicKey, VersionedTransaction, TransactionMessage } from "@solana/web3.js";
import { getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, createTransferInstruction, getAccount } from "@solana/spl-token";

const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const USDC_DECIMALS = 6;

function SendUSDC() {
  const { solana } = useSolana();

  const send = async (to: string, amount: number) => {
    const connection = new Connection("https://api.mainnet-beta.solana.com");
    const from = new PublicKey(await solana.getPublicKey());
    const recipient = new PublicKey(to);

    const fromATA = await getAssociatedTokenAddress(USDC_MINT, from);
    const toATA = await getAssociatedTokenAddress(USDC_MINT, recipient);

    const instructions = [];

    // Create recipient's token account if it doesn't exist
    try {
      await getAccount(connection, toATA);
    } catch {
      instructions.push(
        createAssociatedTokenAccountInstruction(from, toATA, recipient, USDC_MINT)
      );
    }

    // Add transfer instruction
    instructions.push(
      createTransferInstruction(fromATA, toATA, from, amount * 10 ** USDC_DECIMALS)
    );

    const { blockhash } = await connection.getLatestBlockhash();
    const transaction = new VersionedTransaction(
      new TransactionMessage({
        payerKey: from,
        recentBlockhash: blockhash,
        instructions,
      }).compileToV0Message()
    );

    const { signature } = await solana.signAndSendTransaction(transaction);
    return signature;
  };

  return (
    <button onClick={() => send("RECIPIENT_ADDRESS", 10)}>
      Send 10 USDC
    </button>
  );
}

Token addresses

TokenMint AddressDecimals
USDCEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v6
USDTEs9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB6