Code Examples
Fast-track your NWC integration with these examples
TypeScript Project (NodeJS, Browser, React Native)
Install the SDK
npm install @getalby/sdk
or
yarn add @getalby/sdk
Quick Start
You can use the JS SDK LN
class to quickly send and receive payments.
import { LN } from "@getalby/sdk";
const credentials = "nostr+walletconnect://..."; // the NWC connection credentials
const ln = new LN(credentials);
// to send
await ln.pay("lnbc..."); // pay a lightning invoice
// generate an invoice and act upon it once it's paid
const request = await ln.receive({satoshi: 21});
request.onPaid(giveAccess);
Web Project
Bitcoin Connect
See also Bitcoin Connect if you are developing a web application. Bitcoin Connect is a front end library that does the heavily lifting for you. The library includes web components letting users connect from both desktop and mobile devices or make one time payments from wallets that do not yet support NWC.
You can also filter by NWC wallets, allowing users to create a new NWC connection that can be used by your service (for example: ZapPlanner).
Alby JS SDK
The NostrWebLNProvider
exposes the WebLN interface to execute lightning wallet functionality through Nostr Wallet Connect, such as sending payments, making invoices and getting the node balance.
You can explore all the examples here.
Mobile Project
The NWCClient
exposes the NWC interface directly, which is more powerful than the WebLN interface and is recommended if you plan to create an application outside of the web (e.g. native mobile/command line/server backend etc.). See Alby SDK NWCClient documentation.
You find all examples here.
Last updated