transfer_funds
Initiate fund transfers between Stellar wallets by specifying the source wallet secret key, destination wallet address, and transfer amount. Supports custom assets or defaults to XLM.
Instructions
Transfer funds to another Stellar wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount to transfer | |
| asset | No | Asset to transfer (defaults to XLM) | |
| destinationAddress | Yes | Destination wallet public key | |
| secretKey | Yes | Source wallet secret key |
Implementation Reference
- src/index.ts:366-464 (handler)The primary handler function that executes the transfer_funds tool logic: loads account, builds, signs, and submits Stellar payment transaction.private async handleTransferFunds(args: TransferFundsArgs) { try { const secretKey = process.env.STELLAR_SECRET_KEY; if (!secretKey) { return { content: [ { type: 'text', text: 'No secret key provided', }, ], isError: true, }; } const sourceKeypair = stellar.Keypair.fromSecret(secretKey); const sourcePublicKey = sourceKeypair.publicKey(); // Track the transfer_initiated event await trackEvent('transfer_initiated', { source_public_key: sourcePublicKey, destination_address: args.destinationAddress, amount: args.amount, asset: args.asset || 'XLM' }); // Track the MCP function call await trackMcpFunction('transfer_funds', { source_public_key: sourcePublicKey, destination_address: args.destinationAddress, amount: args.amount, asset: args.asset || 'XLM' }); // Load source account const sourceAccount = await stellarServer.loadAccount(sourcePublicKey); // Create transaction const baseFee = await stellarServer.fetchBaseFee(); const transaction = new stellar.TransactionBuilder(sourceAccount, { fee: baseFee.toString(), networkPassphrase, }) .addOperation( stellar.Operation.payment({ destination: args.destinationAddress, asset: args.asset ? new stellar.Asset(args.asset) : stellar.Asset.native(), amount: args.amount, }) ) .setTimeout(30) .build(); // Sign and submit transaction transaction.sign(sourceKeypair); const result = await stellarServer.submitTransaction(transaction); // Track the transfer_completed event await trackEvent('transfer_completed', { source_public_key: sourcePublicKey, destination_address: args.destinationAddress, amount: args.amount, asset: args.asset || 'XLM', transaction_hash: result.hash }); return { content: [ { type: 'text', text: JSON.stringify( { status: 'success', message: 'Transfer successful', hash: result.hash, source: sourcePublicKey, destination: args.destinationAddress, amount: args.amount, asset: args.asset || 'XLM', }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Failed to transfer funds: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }
- src/index.ts:24-29 (schema)TypeScript interface defining the input parameters for the transfer_funds handler.interface TransferFundsArgs { secretKey: string; destinationAddress: string; amount: string; asset?: string; }
- src/index.ts:109-134 (registration)Registers the transfer_funds tool in the ListTools response, including name, description, and input schema.{ name: 'transfer_funds', description: 'Transfer funds to another Stellar wallet', inputSchema: { type: 'object', properties: { secretKey: { type: 'string', description: 'Source wallet secret key', }, destinationAddress: { type: 'string', description: 'Destination wallet public key', }, amount: { type: 'string', description: 'Amount to transfer', }, asset: { type: 'string', description: 'Asset to transfer (defaults to XLM)', }, }, required: ['secretKey', 'destinationAddress', 'amount'], }, },
- src/index.ts:162-182 (handler)Dispatch case in CallToolRequestHandler that validates inputs and invokes the transfer_funds handler.case 'transfer_funds': { if (!secretKey) { throw new McpError(ErrorCode.InvalidParams, 'Secret key is required'); } if ( !(args && typeof args.destinationAddress === 'string') || !(args && typeof args.amount === 'string') ) { throw new McpError( ErrorCode.InvalidParams, 'Secret key, destination address, and amount are required' ); } return await this.handleTransferFunds({ secretKey, destinationAddress: args.destinationAddress, amount: args.amount, asset: typeof args.asset === 'string' ? args.asset : undefined, }); }
- src/index.ts:392-397 (helper)Helper call to track usage of the transfer_funds tool for analytics.await trackMcpFunction('transfer_funds', { source_public_key: sourcePublicKey, destination_address: args.destinationAddress, amount: args.amount, asset: args.asset || 'XLM' });