Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Split NWC client from NostrWeblnProvider #197

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/nwc/client/get-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
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,
});
const response = await client.getInfo();

console.info(response);

client.close();
12 changes: 5 additions & 7 deletions examples/nwc/keysend.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ const rl = readline.createInterface({ input, output });
const nwcUrl =
process.env.NWC_URL ||
(await rl.question("Nostr Wallet Connect URL (nostr+walletconnect://...): "));
const destination =
(await rl.question("Enter destination pubkey: ")) ||
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3";
const amount = await rl.question("Enter amount: ");

rl.close();

const webln = new providers.NostrWebLNProvider({
nostrWalletConnectUrl: nwcUrl,
});
await webln.enable();
const response = await webln.keysend({
amount,
destination,
amount: 1,
destination:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
customRecords: {
696969: "1KOZHzhLs2U7JIx3BmEY",
696969: "017rsl75kNnSke4mMHYE", // hello@getalby.com
},
});

Expand Down
48 changes: 48 additions & 0 deletions examples/nwc/multi-keysend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
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 { webln as providers } 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 webln = new providers.NostrWebLNProvider({
nostrWalletConnectUrl: nwcUrl,
});
await webln.enable();

const keysends = [
{
destination:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
amount: 1,
customRecords: {
696969: "017rsl75kNnSke4mMHYE", // hello@getalby.com
},
},
{
destination:
"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",
amount: 1,
customRecords: {
696969: "1KOZHzhLs2U7JIx3BmEY", // another Alby account
},
},
];

try {
const response = await webln.multiKeysend(keysends);
console.info(response);
} catch (error) {
console.error("multiKeysend failed", error);
}

webln.close();
Loading
Loading