Skip to main content
Glama

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
NameRequiredDescriptionDefault
fromWalletYesName of the sender wallet
toAddressYesRecipient address
tokenMintYesToken mint address
amountYesAmount of tokens to transfer

Implementation Reference

  • 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}` }; }
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ExpertVagabond/solana-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server