transfer
Send SOL tokens securely from one wallet to another using your secret key, destination address, and specified amount on the Solana MCP Server.
Instructions
Transfer SOL from your keypair to another address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount of SOL to send | |
| secretKey | Yes | Your keypair's secret key (as comma-separated numbers or JSON array) | |
| toAddress | Yes | Destination wallet address |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"amount": {
"description": "Amount of SOL to send",
"exclusiveMinimum": 0,
"type": "number"
},
"secretKey": {
"description": "Your keypair's secret key (as comma-separated numbers or JSON array)",
"type": "string"
},
"toAddress": {
"description": "Destination wallet address",
"type": "string"
}
},
"required": [
"secretKey",
"toAddress",
"amount"
],
"type": "object"
}
Implementation Reference
- src/index.ts:215-271 (handler)The handler function that implements the transfer logic: parses secretKey to Keypair, creates SystemProgram.transfer instruction, sends and confirms the transaction, returns success with signature or error.async ({ secretKey, toAddress, amount }) => { try { // Parse the secret key and create keypair let fromKeypair: Keypair; try { // First try parsing as comma-separated string const decoded = Uint8Array.from(secretKey.split(',').map(num => parseInt(num.trim()))); fromKeypair = Keypair.fromSecretKey(decoded); } catch { // If that fails, try as a JSON array string fromKeypair = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(secretKey))); } // Convert SOL amount to lamports const lamports = amount * LAMPORTS_PER_SOL; // Create transfer instruction const transaction = new Transaction().add( SystemProgram.transfer({ fromPubkey: fromKeypair.publicKey, toPubkey: new PublicKey(toAddress), lamports, }) ); // Send and confirm transaction const signature = await sendAndConfirmTransaction( connection, transaction, [fromKeypair] ); return { content: [ { type: "text", text: `Transfer successful! From: ${fromKeypair.publicKey.toBase58()} To: ${toAddress} Amount: ${amount} SOL Transaction signature: ${signature} Explorer URL: https://explorer.solana.com/tx/${signature}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to transfer SOL: ${error.message}`, }, ], }; } }
- src/index.ts:210-214 (schema)Zod schema for 'transfer' tool inputs: secretKey (string), toAddress (string), amount (positive number).{ secretKey: z.string().describe("Your keypair's secret key (as comma-separated numbers or JSON array)"), toAddress: z.string().describe("Destination wallet address"), amount: z.number().positive().describe("Amount of SOL to send"), },
- src/index.ts:207-272 (registration)Registration of the 'transfer' tool via server.tool() call, including name, description, input schema, and handler reference.server.tool( "transfer", "Transfer SOL from your keypair to another address", { secretKey: z.string().describe("Your keypair's secret key (as comma-separated numbers or JSON array)"), toAddress: z.string().describe("Destination wallet address"), amount: z.number().positive().describe("Amount of SOL to send"), }, async ({ secretKey, toAddress, amount }) => { try { // Parse the secret key and create keypair let fromKeypair: Keypair; try { // First try parsing as comma-separated string const decoded = Uint8Array.from(secretKey.split(',').map(num => parseInt(num.trim()))); fromKeypair = Keypair.fromSecretKey(decoded); } catch { // If that fails, try as a JSON array string fromKeypair = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(secretKey))); } // Convert SOL amount to lamports const lamports = amount * LAMPORTS_PER_SOL; // Create transfer instruction const transaction = new Transaction().add( SystemProgram.transfer({ fromPubkey: fromKeypair.publicKey, toPubkey: new PublicKey(toAddress), lamports, }) ); // Send and confirm transaction const signature = await sendAndConfirmTransaction( connection, transaction, [fromKeypair] ); return { content: [ { type: "text", text: `Transfer successful! From: ${fromKeypair.publicKey.toBase58()} To: ${toAddress} Amount: ${amount} SOL Transaction signature: ${signature} Explorer URL: https://explorer.solana.com/tx/${signature}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to transfer SOL: ${error.message}`, }, ], }; } } );