Skip to main content
Glama

close_token_account

Closes a Solana token account to reclaim rent lamports by transferring remaining funds to a specified destination address.

Instructions

Close a token account and reclaim rent

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet that owns the account
tokenMintYesToken mint address
destinationAddressYesAddress to send remaining lamports to

Implementation Reference

  • The handler function that executes the close_token_account tool. It retrieves the wallet, computes the associated token account address, and calls closeAccount from @solana/spl-token to close the account and transfer lamports to the destination.
    async function handleCloseTokenAccount(args: any) { const { walletName, tokenMint, destinationAddress } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); const tokenMintPubkey = new PublicKey(tokenMint); const destinationPubkey = new PublicKey(destinationAddress); const tokenAccount = await getAssociatedTokenAddress( tokenMintPubkey, wallet.keypair.publicKey ); const signature = await closeAccount( connection, wallet.keypair, tokenAccount, destinationPubkey, wallet.keypair ); return { success: true, signature, closedAccount: tokenAccount.toString(), destination: destinationAddress, explorerUrl: `https://explorer.solana.com/tx/${signature}?cluster=${currentNetwork}` }; }
  • src/index.ts:458-479 (registration)
    Registers the close_token_account tool in the tools array, including name, description, and input schema. This array is returned by the ListToolsRequestSchema handler.
    { name: "close_token_account", description: "Close a token account and reclaim rent", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet that owns the account" }, tokenMint: { type: "string", description: "Token mint address" }, destinationAddress: { type: "string", description: "Address to send remaining lamports to" } }, required: ["walletName", "tokenMint", "destinationAddress"] } },
  • Switch case in the main CallToolRequestSchema handler that dispatches to the specific handleCloseTokenAccount function.
    case "close_token_account": result = await handleCloseTokenAccount(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