-
Notifications
You must be signed in to change notification settings - Fork 15
/
zaps.js
28 lines (24 loc) · 1.06 KB
/
zaps.js
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
import { LightningAddress } from "@getalby/lightning-tools";
(async () => {
const ln = new LightningAddress("[email protected]");
await ln.fetch();
if (!ln.nostrPubkey) {
alert("No nostr pubkey available"); // seems the lightning address is no NIP05 address
}
const zapArgs = {
satoshi: 1000,
comment: "Awesome post",
relays: ["wss://relay.damus.io"],
e: "44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245", // optional, omit to zap profile directly
};
if (window.webln) {
// zap in one go with WebLN (https://www.webln.guide) (easiest for web apps)
const response = await ln.zap(zapArgs); // signs zap request event, generates invoice and pays it
console.info(response.preimage); // print the preimage
} else {
// or manually (create an invoice and give it to the user to pay)
const invoice = await ln.zapInvoice(zapArgs); // generates a zap invoice
console.info(invoice.paymentRequest); // print the payment request
await invoice.isPaid(); // check the payment status as described above
}
})();