Making a Payment

In order to make a payment you will need a valid NWC URL. You can create one, or create UI for your users to create one via Alby's NWC app.

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

More Examples

See more examples in the Alby JS SDK Github repository.

Last updated

Logo

Your bitcoin & nostr companion / from 🐝 with 🧡