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

chore: add README for nwc client #230

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: changes
  • Loading branch information
im-adithya committed Jul 10, 2024
commit f92613d7bccd3dd7c49ff14db5ba4f6995f0418f
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or for use without any build tools:

```html
<script type="module">
import { webln } from "https://esm.sh/@getalby/sdk@3.6.0"; // jsdelivr.net, skypack.dev also work
import { webln } from "https://esm.sh/@getalby/sdk@3.6.1"; // jsdelivr.net, skypack.dev also work

(async () => {
const client = new nwc.NWCClient({
Expand Down Expand Up @@ -112,25 +112,12 @@ const client = nwc.NWCClient.withNewSecret({
await client.initNWC();
```

#### sendPayment(invice: string)

Takes a bolt11 invoice and calls the NWC `pay_invoice` function.
It returns a promise object that is resolved with an object with the preimage or is rejected with an error

##### Example

```js
const client = new nwc.NWCClient({ nostrWalletConnectUrl: loadNWCUrl() });
const response = await client.payInvoice({ invoice });
console.log(response);
```

#### getNostrWalletConnectUrl()
#### `getNostrWalletConnectUrl()`

Returns the `nostr+walletconnect://` URL which includes all the connection information (`walletPubkey`, `relayUrl`, `secret`)
This can be used to get and persist the string for later use.

#### initNWC({name: string})
#### `initNWC({ name: string })`

Opens a new window prompt with the `getAuthorizationUrl()` (the user's NWC UI) to ask the user to authorize the app connection.
The promise resolves when the connection is authorized and the popup sends a `nwc:success` message or rejects when the prompt is closed.
Expand All @@ -153,6 +140,21 @@ try {
}
```

#### `payInvoice({ invoice: string })`

Takes a bolt11 invoice and calls the NWC `pay_invoice` function.
It returns a promise object that is resolved with an object with the preimage or is rejected with an error

##### Example

```js
const client = new nwc.NWCClient({ nostrWalletConnectUrl: loadNWCUrl() });
const response = await client.payInvoice({ invoice });
console.log(response);
```

See other [NIP-47 method examples](https://github.com/getAlby/js-sdk/tree/master/examples/nwc/client).

#### For Node.js

To use this on Node.js you first must install `websocket-polyfill` and import it:
Expand Down Expand Up @@ -273,7 +275,7 @@ const nwc = NostrWebLNProvider.withNewSecret();
await nwc.initNWC();
```

#### sendPayment(invice: string)
#### sendPayment(invoice: string)

Takes a bolt11 invoice and calls the NWC `pay_invoice` function.
It returns a promise object that is resolved with an object with the preimage or is rejected with an error
Expand Down
Loading