Skip to content
/ js-sdk Public

JavaScript SDK for the Alby OAuth2 Wallet API and the Nostr Wallet Connect API.

Notifications You must be signed in to change notification settings

getAlby/js-sdk

Repository files navigation

Alby JS SDK

Introduction

Build zero-custody bitcoin payments into apps with a few lines of code.

This JavaScript SDK is for interacting with a bitcoin lightning wallet via Nostr Wallet Connect or the Alby Wallet API.

Installing

npm install @getalby/sdk

or

yarn add @getalby/sdk

or for use without any build tools:

<script type="module">
  import { LN /* or nwc, webln */ } from "https://esm.sh/@getalby/[email protected]"; // jsdelivr.net, skypack.dev also work

  // ... then use the SDK as normal (see below)
</script>

Lightning Network Client (LN) Documentation

Quickly get started adding lightning payments to your app.

The easiest way to provide credentials is with an NWC connection secret. Get one in minutes by connecting to Alby Hub, coinos, Primal, lnwallet.app, Yakihonne, or other NWC-enabled wallets.

For example, to make a payment:

import { LN, USD } from "@getalby/sdk";
const credentials = "nostr+walletconnect://..."; // the NWC connection credentials
await new LN(credentials).pay("lnbc..."); // pay a lightning invoice
await new LN(credentials).pay("[email protected]", USD(1)); // or pay $1 USD to a lightning address

Or to request to receive a payment:

const request = await new LN(credentials).requestPayment(USD(1.0));
// give request.invoice to someone...
request.onPaid(giveAccess);

Read more

For more flexibility you can access the underlying NWC wallet directly. Continue to read the Nostr Wallet Connect documentation below.

Nostr Wallet Connect Documentation

Nostr Wallet Connect is an open protocol enabling applications to interact with bitcoin lightning wallets. It allows users to connect their existing wallets to your application allowing developers to easily integrate bitcoin lightning functionality.

For apps, see NWC client and NWA client documentation

For wallet services, see NWC wallet service documentation

Alby Wallet API Documentation

The Alby OAuth API allows you to integrate bitcoin lightning functionality provided by the Alby Wallet into your applications, with the Alby Wallet API. Send & receive payments, create invoices, setup payment webhooks, access Podcasting 2.0 and more!

Read more

NodeJS

Fetch

This library relies on a global fetch() function which will work in browsers and node v18.x or newer. (In older versions you have to use a polyfill.)

Websocket polyfill

To use this on Node.js you first must install [email protected] and import it:

import "websocket-polyfill";
// or: require('websocket-polyfill');

WebLN Documentation

The JS SDK also has some implementations for WebLN. See the NostrWebLNProvider documentation and OAuthWebLNProvider documentation.

More Documentation

Read the auto-generated documentation

Need help?

We are happy to help, please contact us or create an issue.

Thanks

The client and the setup is inspired and based on the twitter-api-typescript-sdk.

License

MIT