close_token_account
Close 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
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet that owns the account | |
| tokenMint | Yes | Token mint address | |
| destinationAddress | Yes | Address to send remaining lamports to |
Implementation Reference
- src/index.ts:1143-1175 (handler)The handler function that executes the close_token_account tool, using Solana SPL closeAccount to close the associated token account and send lamports to 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:461-478 (schema)Input schema defining parameters for the close_token_account tool: walletName, tokenMint, destinationAddress.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"] }
- src/index.ts:458-479 (registration)Tool registration in the tools array, including name, description, and input schema. Used by 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"] } },
- src/index.ts:1351-1352 (registration)Registration in the main CallToolRequestSchema switch dispatcher that calls the handler.case "close_token_account": result = await handleCloseTokenAccount(args);