Skip to content

Commit

Permalink
Merge pull request #73 from getAlby/feat/nwc-lookup-invoice
Browse files Browse the repository at this point in the history
feat: add lookup invoice to nwc webln provider
  • Loading branch information
rolznz authored Aug 29, 2023
2 parents 332682d + 937295c commit c2e4762
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 119 deletions.
30 changes: 30 additions & 0 deletions examples/nwc/lookup-invoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.lookupInvoice({
// provide one of the below
//invoice: 'lnbc10n1pjwxschpp5hg0pw234n9ww9q4uy25pnvu8y4jzpznysasyf7m9fka36t7fahysdqufet5xgzhv43ycn3qv4uxzmtsd3jscqzzsxqyz5vqsp5uw023qhxuxqfj69rvj9yns5gufczad5gqw4uer5cgqhw90slkavs9qyyssqvv2tw6c30ssgtpejc3zk7ns0svuj8547d8wxj0e36hltljx5a8x4qj59mk2y7qlt6qazf2j38fzc8uag3887nslxz6fe3vnyvg0f2xqqnlvcu2',
payment_hash:
"ba1e172a35995ce282bc22a819b3872564208a64876044fb654dbb1d2fc9edc9",
});

console.info(response);

webln.close();
4 changes: 2 additions & 2 deletions examples/nwc/make-invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const webln = new providers.NostrWebLNProvider({
});
await webln.enable();
const response = await webln.makeInvoice({
amount: 100,
amount: 1, // in sats
defaultMemo: "NWC WebLN example",
});

console.log(response);
console.info(response);

webln.close();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/node": "^18.11.0",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"@webbtc/webln-types": "^1.0.11",
"@webbtc/webln-types": "^2.0.0",
"browserify": "^17.0.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
Loading

0 comments on commit c2e4762

Please sign in to comment.