approve_delegate
Authorize a delegate to transfer specific tokens from your Solana wallet by setting permissions and maximum transfer amounts.
Instructions
Approve a delegate to transfer tokens on your behalf
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet that owns the tokens | |
| tokenMint | Yes | Token mint address | |
| delegateAddress | Yes | Address of the delegate | |
| amount | Yes | Maximum amount delegate can transfer |
Implementation Reference
- src/index.ts:1177-1213 (handler)The core handler function that approves a delegate for transferring up to a specified amount of tokens from the owner's token account using the SPL Token program's approve instruction.async function handleApproveDelegate(args: any) { const { walletName, tokenMint, delegateAddress, amount } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); const tokenMintPubkey = new PublicKey(tokenMint); const delegatePubkey = new PublicKey(delegateAddress); const mintInfo = await getMint(connection, tokenMintPubkey); const rawAmount = BigInt(Math.floor(amount * Math.pow(10, mintInfo.decimals))); const tokenAccount = await getAssociatedTokenAddress( tokenMintPubkey, wallet.keypair.publicKey ); const signature = await approve( connection, wallet.keypair, tokenAccount, delegatePubkey, wallet.keypair, rawAmount ); return { success: true, signature, delegate: delegateAddress, amount, explorerUrl: `https://explorer.solana.com/tx/${signature}?cluster=${currentNetwork}` }; }
- src/index.ts:480-505 (schema)Input schema definition for the approve_delegate tool, specifying parameters for wallet, token mint, delegate, and amount.{ name: "approve_delegate", description: "Approve a delegate to transfer tokens on your behalf", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet that owns the tokens" }, tokenMint: { type: "string", description: "Token mint address" }, delegateAddress: { type: "string", description: "Address of the delegate" }, amount: { type: "number", description: "Maximum amount delegate can transfer" } }, required: ["walletName", "tokenMint", "delegateAddress", "amount"] } },
- src/index.ts:1354-1356 (registration)Switch case in the main CallToolRequestSchema handler that registers and dispatches to the approve_delegate handler function.case "approve_delegate": result = await handleApproveDelegate(args); break;