zap
Use this tool to send satoshis to a user via their npub or NIP-05 identifier on Nostr, enabling instant microtransactions with an optional comment.
Instructions
Send a zap to a user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount in satoshis | |
| comment | No | Optional comment | |
| recipient | Yes | User npub or NIP-05 identifier to zap |
Implementation Reference
- wallet.ts:663-688 (handler)MCP tool handler for the 'zap' tool. Parses arguments, validates inputs, calls the wallet's zap method, and formats the response.case 'zap': const { recipient, amount: zapAmount, comment = '' } = args; if (!recipient || !zapAmount) { throw new Error('recipient and amount are required'); } const zapResult = await this.wallet.zap(recipient, zapAmount, comment); if (zapResult && zapResult.success !== false) { return { content: [{ type: 'text', text: `Successfully zapped ${zapAmount} sats to ${recipient}` }], success: true, recipient, amount: zapAmount, comment, zapResult }; } else { return { content: [{ type: 'text', text: `Failed to zap ${zapAmount} sats to ${recipient}` }], success: false, recipient, amount: zapAmount, comment, zapResult }; }
- wallet.ts:440-476 (helper)Core implementation of the zap functionality in MCPWallet class. Resolves recipient pubkey, creates NDKZapper instance, and executes the zap.async zap(recipient: string, amount: number, comment: string = ''): Promise<any> { if (!this.ndk || !this.wallet) throw new Error('NDK or wallet not initialized'); try { let user; // Check if recipient looks like a pubkey (npub or hex) if (recipient.startsWith('npub') || (recipient.length === 64 && /^[0-9a-f]+$/i.test(recipient))) { // Direct pubkey - use as is user = this.ndk.getUser({ npub: recipient.startsWith('npub') ? recipient : nip19.npubEncode(recipient) }); } else { // Assume it's a NIP-05 identifier and try to resolve it try { user = await this.ndk.getUserFromNip05(recipient); if (!user) { throw new Error(`Could not resolve NIP-05 identifier: ${recipient}`); } } catch (nip05Error) { throw new Error(`Failed to resolve NIP-05 identifier "${recipient}": ${nip05Error instanceof Error ? nip05Error.message : 'Unknown error'}`); } } // Use NDK's built-in zapping with the configured wallet const zapper = new NDKZapper(user, amount * 1000, "msat", { ndk: this.ndk, comment: comment }); const zapResult = await zapper.zap(); this.saveWallet(); return zapResult; } catch (error) { console.error('Error sending zap:', error); throw error; } }
- wallet.ts:573-584 (schema)Input schema definition for the 'zap' tool, including parameters and validation rules.name: 'zap', description: 'Send a zap to a user', inputSchema: { type: 'object', properties: { recipient: { type: 'string', description: 'User npub or NIP-05 identifier to zap' }, amount: { type: 'number', description: 'Amount in satoshis' }, comment: { type: 'string', description: 'Optional comment' } }, required: ['recipient', 'amount'] } },
- wallet.ts:529-597 (registration)Tool list registration in the ListToolsRequestSchema handler, where the 'zap' tool is declared alongside other tools.return { tools: [ { name: 'get_balance', description: 'Get the total wallet balance', inputSchema: { type: 'object', properties: {}, required: [] } }, { name: 'get_mint_balances', description: 'Get balance breakdown per mint', inputSchema: { type: 'object', properties: {}, required: [] } }, { name: 'deposit', description: 'Create a deposit invoice (bolt11) for the specified amount and mint. Returns the invoice immediately for payment. If no mint is specified, all mints will be tried concurrently and the first successful response will be used.', inputSchema: { type: 'object', properties: { amount: { type: 'number', description: 'Amount in satoshis' }, mintUrl: { type: 'string', description: 'Mint URL to deposit to (optional - all mints tried concurrently if not provided)' } }, required: ['amount'] } }, { name: 'pay', description: 'Pay a Lightning invoice', inputSchema: { type: 'object', properties: { bolt11: { type: 'string', description: 'Lightning invoice to pay' } }, required: ['bolt11'] } }, { name: 'zap', description: 'Send a zap to a user', inputSchema: { type: 'object', properties: { recipient: { type: 'string', description: 'User npub or NIP-05 identifier to zap' }, amount: { type: 'number', description: 'Amount in satoshis' }, comment: { type: 'string', description: 'Optional comment' } }, required: ['recipient', 'amount'] } }, { name: 'add_mint', description: 'Add a mint to the wallet', inputSchema: { type: 'object', properties: { mintUrl: { type: 'string', description: 'Mint URL to add' } }, required: ['mintUrl'] } } ] };