Skip to content

Commit

Permalink
book: add Python & JS NIP47 examples
Browse files Browse the repository at this point in the history
Move `nwc.py` and `nwc.js` examples to the book and extend them.

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 19, 2024
1 parent 4d1474d commit 6c03bb2
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* connect: add `NostrConnect::non_secure_set_user_public_key` ([Yuki Kishimoto])
* ffi: add `make_private_msg` func ([Yuki Kishimoto])
* ffi: add `CustomNostrSigner` trait ([Yuki Kishimoto])
* book: add some examples ([RydalWater])
* book: add some examples ([RydalWater] and [Yuki Kishimoto])

### Fixed

Expand Down
24 changes: 0 additions & 24 deletions bindings/nostr-sdk-ffi/python/examples/nwc.py

This file was deleted.

26 changes: 0 additions & 26 deletions bindings/nostr-sdk-js/examples/nwc.js

This file was deleted.

31 changes: 31 additions & 0 deletions book/snippets/js/src/nip47.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ANCHOR: full
import { NWC, NostrWalletConnectURI, MakeInvoiceRequestParams } from "@rust-nostr/nostr-sdk";

export async function main() {
// Parse NWC uri
let uri = NostrWalletConnectURI.parse("nostr+walletconnect://..");

// Initialize NWC client
let nwc = new NWC(uri);

// Get info
let info = await nwc.getInfo();
console.log("Supported methods: ", info.methods);

// Get balance
let balance = await nwc.getBalance();
console.log("Balance: " + balance + " SAT");

// Pay an invoice
await nwc.payInvoice("lnbc..")

// Make an invoice
let params = new MakeInvoiceRequestParams();
params.amount = BigInt(100);
const result = await nwc.makeInvoice(params)
console.log("Invoice: " + result.invoice);

// Drop client
nwc.free();
}
// ANCHOR_END: full
28 changes: 28 additions & 0 deletions book/snippets/python/src/nip47.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ANCHOR: full
from nostr_sdk import NostrWalletConnectUri, Nwc, MakeInvoiceRequestParams


async def main():
# Parse NWC uri
uri = NostrWalletConnectUri.parse("nostr+walletconnect://..")

# Initialize NWC client
nwc = Nwc(uri)

# Get info
info = await nwc.get_info()
print(info)

# Get balance
balance = await nwc.get_balance()
print(f"Balance: {balance} SAT")

# Pay an invoice
await nwc.pay_invoice("lnbc..")

# Make an invoice
params = MakeInvoiceRequestParams(amount=100, description=None, description_hash=None, expiry=None)
result = await nwc.make_invoice(params)
print(f"Invoice: {result.invoice}")

# ANCHOR_END: full
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [NIP-19: bech32-encoded entities](sdk/nips/19.md)
* [NIP-21: nostr URI scheme](sdk/nips/21.md)
* [NIP-44: Encrypted Payloads](sdk/nips/44.md)
* [NIP-47: Nostr Wallet Connect](sdk/nips/47.md)
* [NIP-59: Gift Wrap](sdk/nips/59.md)
* [NIP-65: Relay List Metadata](sdk/nips/65.md)

Expand Down
52 changes: 52 additions & 0 deletions book/src/sdk/nips/47.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## NIP-47: Nostr Wallet Connect

### Full example

<custom-tabs category="lang">

<div slot="title">Rust</div>
<section>

TODO

</section>

<div slot="title">Python</div>
<section>

```python,ignore
{{#include ../../../snippets/python/src/nip47.py:full}}
```

</section>

<div slot="title">JavaScript</div>
<section>

```typescript,ignore
{{#include ../../../snippets/js/src/nip47.ts:full}}
```

</section>

<div slot="title">Kotlin</div>
<section>

TODO

</section>

<div slot="title">Swift</div>
<section>

TODO

</section>

<div slot="title">Flutter</div>
<section>

TODO

</section>
</custom-tabs>
1 change: 0 additions & 1 deletion book/src/sdk/nwc.md

This file was deleted.

0 comments on commit 6c03bb2

Please sign in to comment.