Alby Developer Guide
User GuideDeveloper Portal
NWC API
NWC API
  • Introduction
    • ❔What is Nostr Wallet Connect?
  • Building Lightning Apps
    • ⛓️NWC HTTP API
      • ℹ️Fetch NWC Info
      • 📢Publish NWC Request
      • ✍️Publish Event
      • 📩Subscribe to Events
      • 🔔Subscribe to NWC Notifications
      • 🔕Delete Subscriptions
      • ↔️Code examples: Creating Requests
    • ⚡NWC JS SDK
  • Building NWC Wallet Services
    • 🗼Alby NWC Relay
Powered by GitBook
LogoLogo

Our content

  • Website
  • Blog
  • GitHub

Follow us

  • Nostr
  • Twitter / X
  • Youtube

Contact us

  • E-mail
  • Community Chat
  • Open Hours

Your bitcoin & nostr companion / from 🐝 with 🧡

On this page
  • NostrWebLNProvider (aliased as NWC) Options
  • Payments with an existing NWC URL
  • Allowing Users to Create a new NWC URL
  • NostrWebLNProvider Functions
  • More Examples

Was this helpful?

  1. Building Lightning Apps

NWC JS SDK

Last updated 11 months ago

Was this helpful?

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

The NostrWebLNProvider exposes the 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

  • 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 .

  2. Create your NWC connection string at .

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

More Examples

See more functions in the NWC JS SDK .

See more examples in the NWC JS SDK .

⚡
WebLN
spec
this link
nwc.getalby.com
GitHub repository
GitHub repository