Skip to main content

▶ Watch the flow first

Interactive terminal demo — see install → 402 → Lightning pay → 200 OK, end to end.

1. Get a free Lightning wallet

Sign up at dashboard.blink.sv — free, no credit card, works globally. Copy your API Key and BTC Wallet ID.

2. Install

npm install l402-kit

3. Add to your API

import express from "express";
import { l402, BlinkProvider } from "l402-kit";

const app = express();

const lightning = new BlinkProvider(
  process.env.BLINK_API_KEY!,
  process.env.BLINK_WALLET_ID!,
);

app.get("/", (_req, res) => {
  res.json({ message: "Welcome!" });
});

// Costs 100 sats per call
app.get("/premium", l402({ priceSats: 100, lightning }), (_req, res) => {
  res.json({ data: "You paid 100 sats. Here is your data." });
});

app.listen(3000);

4. Test it

curl http://localhost:3000/premium
Response:
{
  "error": "Payment Required",
  "price_sats": 100,
  "invoice": "lnbc1u1p...",
  "macaroon": "eyJoYXNo..."
}
Pay the invoice with any Lightning wallet, then:
curl http://localhost:3000/premium \
  -H "Authorization: L402 <macaroon>:<preimage>"
Response:
{ "data": "You paid 100 sats. Here is your data." }
Your API now accepts Bitcoin payments.