-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1.18 KB
/
index.js
File metadata and controls
40 lines (35 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
import express from "express";
import ZbdPayments from "@zbddev/payments-sdk";
const ZBD_API_KEY = 'b7YW3s2JzZKGcXjIf5Dqof8wjKT2RuWr8'; // TODO: Replace with your own API key
const client = new ZbdPayments({ apikey: ZBD_API_KEY });
// Create Express app
const app = express();
// Creating a Bitcoin Lightning payment request
app.get("/request", async (_req, res) => {
try {
const data = await client.lightningCharges.create({
amount: "100000", // 100 satoshis (100,000 msats)
description: "Express + ZBD!",
callbackUrl: "https://your-app.com/callback",
});
res.status(200).json({ data });
} catch (error) {
res.status(500).json({ error });
}
});
// Send a payment to a Bitcoin Lightning Address
app.get("/send", async (_req, res) => {
try {
const data = await client.lightningAddress.sendPayment({
lnAddress: "andre@zbd.gg", // Who is the recipient?
amount: "100000", // 100 satoshis (100,000 msats)
comment: "Express + ZBD!",
});
res.status(200).json({ data });
} catch (error) {
res.status(500).json({ error });
}
});
app.listen(3005, () => {
console.log("Express server w/ ZBD listening on http://localhost:3005");
});