@getalby/sdk

中文文档
9.0.0发布于 2026/10/27MITTypeScriptESM + CJS构建来源已验证近 30 天下载 9.5万

The SDK to integrate with Nostr Wallet Connect and the Alby API

原始使用文档
文档目录12 节
  1. Introduction
  2. 🤖 🚀 ⚡ For Developers using Agents / LLMs / Vibe Coding
  3. Manual Installation
  4. Lightning Network Client (LN) Documentation
  5. Nostr Wallet Connect Documentation
  6. Alby Wallet API Documentation
  7. NodeJS
  8. WebLN Documentation
  9. More Documentation
  10. Need help?
  11. Thanks
  12. License

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.

Before you start coding, look at example scenarios in our Developer Sandbox

🤖 🚀 ⚡ For Developers using Agents / LLMs / Vibe Coding

Skip the rest of this README and use the Alby Bitcoin Builder Skill to build a bitcoin app or the Alby Bitcoin Payment Skill to give your agent payment capabilities. It will handle the rest!

Manual Installation

npm install @getalby/sdk

or

yarn add @getalby/sdk

or for use without any build tools:

<script type="module">
  import {
    LN /* or NWCClient, or NostrWebLNProvider */,
  } 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/lnclient";
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

Node.js 22 or higher is required (for native fetch and WebSocket support). On older versions you can install and import [email protected] before using the SDK (not recommended).

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

版本与发布记录

@getalby/sdk 共发布 65 个版本,首次发布于 2023/08/08;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.0.0latest2026/10/2720 天前
8.1.12026/10/2125 天前
8.1.02026/10/2026 天前
8.0.32026/05/205 个月前
8.0.12026/05/156 个月前
7.0.02025/11/071 年前

其他发布通道:beta → 6.1.0-beta.0。

关于 @getalby/sdk 的常见问题

@getalby/sdk 是什么?

The SDK to integrate with Nostr Wallet Connect and the Alby API

如何安装 @getalby/sdk?

在项目目录运行 npm install @getalby/sdk,或使用 pnpm add / yarn add / bun add。

@getalby/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@getalby/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@getalby/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@getalby/sdk 可以商用吗?

@getalby/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@getalby/sdk 的下载量有多少?

根据 npm 官方下载统计,@getalby/sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 95,019 次,日均约 3,167 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@getalby/sdk 还在维护吗?

最新版本 9.0.0 发布于 2026/10/27(20 天前);至今共发布 65 个版本,其中过去 12 个月发布了 5 个;首次发布于 2023/08/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。