Skip to content

Commit

Permalink
chore: add examples for make-invoice and get-balance
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Aug 10, 2023
1 parent f92ba8b commit e784926
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
21 changes: 21 additions & 0 deletions examples/nwc/get-balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 = await rl.question('Nostr Wallet Connect URL (nostrwalletconnect://...): ');
rl.close();

const webln = new providers.NostrWebLNProvider({ nostrWalletConnectUrl: nwcUrl });
await webln.enable();
const response = await webln.getBalance();

console.log(response);

webln.close();
24 changes: 24 additions & 0 deletions examples/nwc/make-invoice.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 { webln as providers } from "../../dist/index.module.js";

const rl = readline.createInterface({ input, output });

const nwcUrl = await rl.question('Nostr Wallet Connect URL (nostrwalletconnect://...): ');
rl.close();

const webln = new providers.NostrWebLNProvider({ nostrWalletConnectUrl: nwcUrl });
await webln.enable();
const response = await webln.makeInvoice({
amount: 100,
defaultMemo: "NWC WebLN example"
});

console.log(response);

webln.close();
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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";
import { webln as providers } from "../../dist/index.module.js";

const rl = readline.createInterface({ input, output });

Expand Down

0 comments on commit e784926

Please sign in to comment.