-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathnwa.js
41 lines (28 loc) · 1.04 KB
/
nwa.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
import "websocket-polyfill"; // required in node.js
import qrcode from "qrcode-terminal";
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { nwa } from "../../../dist/index.module.js";
const rl = readline.createInterface({ input, output });
const DEFAULT_RELAY_URL = "wss://relay.getalby.com/v1";
const relayUrl =
(await rl.question(`Relay URL (${DEFAULT_RELAY_URL}): `)) ||
DEFAULT_RELAY_URL;
rl.close();
const nwaClient = new nwa.NWAClient({
relayUrl,
requestMethods: ["get_info"],
});
console.info("Scan or enter the following NWA connection URI in your wallet:");
// this prints the QR code
qrcode.generate(nwaClient.connectionUri, { small: true });
console.info(nwaClient.connectionUri);
console.info("\nWaiting for connection...");
await nwaClient.subscribe({
onSuccess: async (nwcClient) => {
console.info("NWA successful", nwcClient.options);
const response = await nwcClient.getInfo();
console.info(response);
nwcClient.close();
},
});