Comment on page
⚡
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.
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()
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
Last modified 6mo ago