transfer_tokens
Transfer SPL tokens between Solana wallets by specifying sender, recipient address, token mint, and amount to send.
Instructions
Transfer SPL tokens between wallets
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromWallet | Yes | Name of the sender wallet | |
| toAddress | Yes | Recipient address | |
| tokenMint | Yes | Token mint address | |
| amount | Yes | Amount of tokens to transfer |
Implementation Reference
- src/index.ts:671-724 (handler)The handler function that executes the transfer_tokens tool. It retrieves the sender wallet, computes associated token accounts, creates recipient's ATA if missing, adds transfer instruction, signs and sends the transaction on Solana.async function handleTransferTokens(args: any) { const { fromWallet, toAddress, tokenMint, amount } = args; const wallet = wallets.get(fromWallet); if (!wallet) { throw new Error(`Wallet '${fromWallet}' not found`); } ensureConnection(); const tokenMintPubkey = new PublicKey(tokenMint); const toPubkey = new PublicKey(toAddress); const fromTokenAccount = await getAssociatedTokenAddress(tokenMintPubkey, wallet.keypair.publicKey); const toTokenAccount = await getAssociatedTokenAddress(tokenMintPubkey, toPubkey); const transaction = new Transaction(); // Check if recipient has token account, create if not try { await getAccount(connection, toTokenAccount); } catch { transaction.add( createAssociatedTokenAccountInstruction( wallet.keypair.publicKey, toTokenAccount, toPubkey, tokenMintPubkey ) ); } transaction.add( createTransferInstruction( fromTokenAccount, toTokenAccount, wallet.keypair.publicKey, BigInt(Math.floor(amount)) ) ); const { blockhash } = await connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.feePayer = wallet.keypair.publicKey; transaction.sign(wallet.keypair); const signature = await connection.sendTransaction(transaction, [wallet.keypair]); return { success: true, signature, explorerUrl: `https://explorer.solana.com/tx/${signature}?cluster=${currentNetwork}` }; }
- src/index.ts:168-192 (schema)The schema definition for the transfer_tokens tool, including name, description, and input schema parameters.{ name: "transfer_tokens", description: "Transfer SPL tokens between wallets", inputSchema: { type: "object", properties: { fromWallet: { type: "string", description: "Name of the sender wallet" }, toAddress: { type: "string", description: "Recipient address" }, tokenMint: { type: "string", description: "Token mint address" }, amount: { type: "number", description: "Amount of tokens to transfer" } }, required: ["fromWallet", "toAddress", "tokenMint", "amount"] }
- src/index.ts:1303-1304 (registration)The registration/dispatch point in the switch statement within the CallToolRequestSchema handler that routes calls to the transfer_tokens handler function.case "transfer_tokens": result = await handleTransferTokens(args);