Skip to content

Commit 761d172

Browse files
authored
chore: add esm ln example (#365)
1 parent f8dbebc commit 761d172

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/lnclient/paywall-esm.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script type="module">
2+
import { LN, USD } from "https://esm.sh/@getalby/[email protected]"; // jsdelivr.net, skypack.dev also work
3+
const connectionSecret = prompt("Enter a read-only connection secret");
4+
const client = new LN(connectionSecret);
5+
6+
// request a lightning invoice that we show the user to pay
7+
const request = await client.requestPayment(USD(1.0), {
8+
description: "best content",
9+
});
10+
11+
prompt(
12+
"Please copy and pay the above invoice. Once you close the dialog, make sure to pay the invoice within 60 seconds.",
13+
request.invoice.paymentRequest,
14+
);
15+
16+
// once the invoice got paid by the user run this callback
17+
request
18+
.onPaid(() => {
19+
alert("received payment!");
20+
client.close(); // when done and no longer needed close the wallet connection
21+
})
22+
.onTimeout(60, () => {
23+
alert("didn't receive payment in time.");
24+
client.close(); // when done and no longer needed close the wallet connection
25+
});
26+
</script>

0 commit comments

Comments
 (0)