-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmulti-pay-keysend.js
79 lines (69 loc) · 2.05 KB
/
multi-pay-keysend.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import "websocket-polyfill"; // required in node.js
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { nwc } from "../../../dist/index.module.js";
const rl = readline.createInterface({ input, output });
const nwcUrl =
process.env.NWC_URL ||
(await rl.question("Nostr Wallet Connect URL (nostr+walletconnect://...): "));
rl.close();
const client = new nwc.NWCClient({
nostrWalletConnectUrl: nwcUrl,
});
// Data from https://podcastindex.org/podcast/920666
const boost = {
action: "boost",
value_msat: 1000,
value_msat_total: 1000,
app_name: "⚡ WebLN Demo",
app_version: "1.0",
feedID: "https://feeds.podcastindex.org/pc20.xml",
podcast: "Podcasting 2.0",
episode: "Episode 104: A New Dump",
ts: 21,
name: "⚡ WebLN Demo",
sender_name: "Satoshi Nakamoto",
message: "Go podcasting!",
};
// from https://stackoverflow.com/a/50868276
const toHexString = (bytes) =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
const keysends = [
{
pubkey:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
amount: 1000, // millisats
tlv_records: [
{
type: 696969,
value: toHexString(new TextEncoder().encode("017rsl75kNnSke4mMHYE")), // hello@getalby.com
},
{
type: 7629169,
value: toHexString(new TextEncoder().encode(JSON.stringify(boost))),
},
],
},
{
pubkey:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
amount: 1000, // millisats
tlv_records: [
{
type: 696969,
value: toHexString(new TextEncoder().encode("1KOZHzhLs2U7JIx3BmEY")), // another Alby account
},
{
type: 7629169,
value: toHexString(new TextEncoder().encode(JSON.stringify(boost))),
},
],
},
];
try {
const response = await client.multiPayKeysend({ keysends });
console.info(JSON.stringify(response));
} catch (error) {
console.error("multi_pay_keysend failed", error);
}
client.close();