⚡NWC JS SDK

The Alby JS SDK allows you to quickly integrate NWC into any JavaScript based application.

The NostrWebLNProvider exposes the WebLN interface to execute lightning wallet functionality through NWC, such as sending payments, making invoices and getting the node balance.

NostrWebLNProvider (aliased as NWC) Options

  • providerName: name of the provider to load the default options. currently alby (default)

  • nostrWalletConnectUrl: full Nostr Wallet Connect URL as defined by the spec

  • relayUrl: URL of the Nostr relay to be used (e.g. wss://nostr-relay.getalby.com)

  • walletPubkey: pubkey of the Nostr Wallet Connect app

  • secret: secret key to sign the request event (if not available window.nostr will be used)

  • authorizationUrl: URL to the NWC interface for the user to and the app connection

Example NWC URL

nostr+walletconnect://69effe7b49a6dd5cf525bxxxxxx17a5005ffe480b58eeb8e861418cf3ae760d9?relay=wss://relay.getalby.com/v1&secret=52c6dfcfa4bbc2bd3609ffe12eaff4xxxxxx8f7fe7ddfbc837a8af5ca0871b4a&lud16=moritz@getalby.com

Note: A lightning address that clients can use to automatically setup the lud16 field on the user's profile if they have none configured is optional

If you need an own NWC connection string for testing:

  1. Get an Alby Account with this link.

  2. Create your NWC connection string at nwc.getalby.com.

Payments with an existing NWC URL

import { webln } from "alby-js-sdk";

const nwc = new webln.NWC({ nostrWalletConnectUrl: "<your-NWC-URL-here>" });

// connect to the relay
await nwc.enable();

// now you can send payments by passing in the invoice
const response = await nwc.sendPayment(invoice);

// disconnect from the relay
nwc.close()

Allowing Users to Create a new NWC URL

If you wish your users to create a brand new NWC connection for using your service, you can launch a NWC modal where your user can confirm the connection:


const nwc = webln.NostrWebLNProvider.withNewSecret();

await nwc.initNWC({
  name: "<Your service name here>",
});
const url = nwc.getNostrWalletConnectUrl(true);

// ... safely store or use the URL to make a payment

NostrWebLNProvider Functions

See more functions in the NWC JS SDK GitHub repository.

More Examples

See more examples in the NWC JS SDK GitHub repository.

Last updated

Logo

Your bitcoin & nostr companion / from 🐝 with 🧡