@getalby/sdk
    Preparing search index...

    @getalby/sdk

    Alby JS SDK

    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.

    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/sdk@5.0.0"; // jsdelivr.net, skypack.dev also work

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

    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("hello@getalby.com", 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 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

    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

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

    To use this on Node.js you first must install websocket-polyfill@0.0.3 and import it:

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

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

    Read the auto-generated documentation

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

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

    MIT