deposit
Generate a Lightning Network invoice (bolt11) to deposit satoshis into Cashu mints, enabling AI agents to receive payments via Nostr.
Instructions
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.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount in satoshis | |
| mintUrl | No | Mint URL to deposit to (optional - all mints tried concurrently if not provided) |
Implementation Reference
- wallet.ts:550-561 (registration)Registration of the 'deposit' tool in the ListTools response, including name, description, and input schema definition.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'] } }, {
- wallet.ts:623-639 (handler)Tool handler in callTool switch statement: validates input, calls wallet.createDepositInvoice, and returns formatted response with invoice details.case 'deposit': const { amount, mintUrl } = args; if (!amount) { throw new Error('Amount is required'); } const invoice = await this.wallet.createDepositInvoice(amount, mintUrl); return { content: [{ type: 'text', text: `Deposit invoice created. Pay this invoice: ${invoice.bolt11}` }], invoice: invoice.bolt11, amount: invoice.amount, mintUrl: invoice.mintUrl, depositId: invoice.depositId };
- wallet.ts:271-312 (helper)Core implementation of deposit invoice creation: selects mint, initiates NDKCashuDeposit, generates invoice and unique depositId, sets up event listeners for success/error.async createDepositInvoice(amount: number, mintUrl?: string): Promise<{ bolt11: string; amount: number; mintUrl: string; depositId: string }> { if (!this.wallet || !this.walletData) throw new Error('Wallet not initialized'); try { // If no mint URL provided, use first available mint if (!mintUrl) { if (!this.walletData.mints || this.walletData.mints.length === 0) { throw new Error('No mints configured. Please add a mint first.'); } mintUrl = this.walletData.mints[0]; } // Add mint to wallet configuration if not already present if (!this.walletData.mints.includes(mintUrl)) { this.walletData.mints.push(mintUrl); this.wallet.mints = this.walletData.mints; this.saveWallet(); } const deposit: NDKCashuDeposit = this.wallet.deposit(amount, mintUrl); const invoice = await deposit.start(); // Generate unique ID for tracking this deposit const depositId = `deposit_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; // Set up background monitoring for this deposit deposit.on("success", () => { console.log(`✅ Deposit ${depositId} completed successfully`); this.saveWallet(); }); deposit.on("error", (error) => { console.error(`❌ Deposit ${depositId} failed:`, error); }); return { bolt11: invoice, amount, mintUrl, depositId }; } catch (error) { console.error('Error creating deposit invoice:', error); throw error; } }