Skip to main content
Glama

transfer_tokens

Transfer SPL tokens between Solana wallets by specifying sender, recipient address, token mint, and amount.

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 SPL token transfer. It retrieves the sender's wallet, computes associated token accounts, optionally creates the recipient's ATA, builds and signs a transaction with transfer instruction, and sends it.
    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 input schema definition and tool metadata for transfer_tokens, part of the tools array used for registration and validation.
    { 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 dispatch case in the MCP CallToolRequest 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