zap
Send Bitcoin payments to users via Nostr using satoshis. Specify recipient and amount to transfer funds with optional comments.
Instructions
Send a zap to a user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| recipient | Yes | User npub or NIP-05 identifier to zap | |
| amount | Yes | Amount in satoshis | |
| comment | No | Optional comment |
Implementation Reference
- wallet.ts:440-476 (handler)Core handler function that implements the zap tool logic using NDKZapper to send zaps to Nostr users.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:572-584 (registration)Registration of the 'zap' tool in the MCP listTools handler, defining name, description, and input schema.{ 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:663-688 (handler)MCP callTool request handler case for 'zap' that validates arguments and calls the wallet.zap method.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 }; }