-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
book: add Python & JS NIP47 examples
Move `nwc.py` and `nwc.js` examples to the book and extend them. Signed-off-by: Yuki Kishimoto <[email protected]>
- Loading branch information
Showing
8 changed files
with
113 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.