-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmulti-pay-invoice.ts
More file actions
50 lines (39 loc) · 1.18 KB
/
multi-pay-invoice.ts
File metadata and controls
50 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import "websocket-polyfill"; // required in node.js
import { LightningAddress } from "@getalby/lightning-tools";
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { NWCClient } from "@getalby/sdk/nwc";
const rl = readline.createInterface({ input, output });
const ln = new LightningAddress(process.env.LN_ADDRESS || "hello@getalby.com");
// fetch the LNURL data
await ln.fetch();
// generate 2 invoices to pay
const invoices = (
await Promise.all(
[1, 2].map((v) =>
ln.requestInvoice({
satoshi: 1,
comment: `Multi-pay invoice #${v}`,
}),
),
)
).map((invoice) => invoice.paymentRequest);
console.info("Generated two invoices", invoices);
const nwcUrl =
process.env.NWC_URL ||
(await rl.question("Nostr Wallet Connect URL (nostr+walletconnect://...): "));
rl.close();
const client = new NWCClient({
nostrWalletConnectUrl: nwcUrl,
});
try {
const response = await client.multiPayInvoice({
invoices: invoices.map((invoice) => ({
invoice,
})),
});
console.info(response);
} catch (error) {
console.error("multi_pay_invoice failed", error);
}
client.close();