NIP-47: Nostr Wallet Connect
Full example
Rust
use nostr_sdk::prelude::*;
pub async fn run() -> Result<()> {
// Parse NWC uri
let uri = NostrWalletConnectURI::parse("nostr+walletconnect://..")?;
// Initialize NWC client
let nwc = NWC::new(uri);
// Get info
let info = nwc.get_info().await?;
println!("Supported methods: {:?}", info.methods);
// Get balance
let balance = nwc.get_balance().await?;
println!("Balance: {balance} SAT");
// Pay an invoice
nwc.pay_invoice("lnbc..").await?;
// Make an invoice
let params = MakeInvoiceRequestParams {
amount: 100,
description: None,
description_hash: None,
expiry: None,
};
let result = nwc.make_invoice(params).await?;
println!("Invoice: {}", result.invoice);
Ok(())
}
Python
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}")
JavaScript
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();
}
Kotlin
import rust.nostr.sdk.*
suspend fun nip47() {
// Parse NWC uri
val uri = NostrWalletConnectUri.parse("nostr+walletconnect://..")
// Initialize NWC client
val nwc = Nwc(uri)
// Get info
val info = nwc.getInfo()
println("Supported methods: ${info.methods}")
// Get balance
val balance = nwc.getBalance()
println("Balance: $balance SAT")
// Pay an invoice
nwc.payInvoice("lnbc..")
// Make an invoice
val params = MakeInvoiceRequestParams(amount = 100u, description = null, descriptionHash = null, expiry = null)
val result = nwc.makeInvoice(params)
println("Invoice: ${result.invoice}")
}
Swift
TODO
Flutter
TODO