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
    let params = PayInvoiceRequest::new("lnbc..");
    nwc.pay_invoice(params).await?;

    // Make an invoice
    let params = MakeInvoiceRequest {
        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, PayInvoiceRequest, MakeInvoiceRequest


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
    params = PayInvoiceRequest(invoice = "lnbc..", id = None, amount = None)
    await nwc.pay_invoice(params)

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

JavaScript
import { NWC, NostrWalletConnectURI, PayInvoiceRequest, MakeInvoiceRequest } 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
    let payInvoiceParams = new PayInvoiceRequest();
    payInvoiceParams.invoice = "lnbc..";
    await nwc.payInvoice(payInvoiceParams);

    // Make an invoice
    let makeInvoiceParams = new MakeInvoiceRequest();
    makeInvoiceParams.amount = BigInt(100);
    const result = await nwc.makeInvoice(makeInvoiceParams)
    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
    val payInvoiceParams = PayInvoiceRequest(invoice = "lnbc...", amount = null, id = null)
    nwc.payInvoice(payInvoiceParams)

    // Make an invoice
    val makeInvoiceParams = MakeInvoiceRequest(amount = 100u, description = null, descriptionHash = null, expiry = null)
    val result = nwc.makeInvoice(makeInvoiceParams)
    println("Invoice: ${result.invoice}")
}
Swift

TODO

Flutter

TODO