Sending SPL tokens is a common transaction on the Solana blockchain. This recipe walks you through creating and sending SPL token transfer transactions using @solana/spl-token and @solana/web3.js with Privy wallets. In this example, we’ll use USDC as the SPL token, but you can adapt it for any SPL token by changing the mint address and decimals.
You can send the transaction using Privy’s different SDKs. Below are examples for React, React Native, NodeJS, and Python:
Report incorrect code
Copy
Ask AI
import {useSendTransaction, useWallets} from '@privy-io/react-auth/solana';const {wallets} = useWallets();const {sendTransaction} = useSendTransaction();const {transaction, connection} = await createSPLTransferTransaction( wallets[0].address, 'recipient-wallet-address', // Replace with recipient's token account address 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC mint address 10 // Amount to send);// Assuming you have a transaction created from the previous stepconst signature = await sendTransaction({ transaction, // from createSPLTransferTransaction address: wallets[0].address, connection // from createSPLTransferTransaction});