Skip to main content

?? ?? l402-kit?

l402-kit ?? middleware ????? ?????? ???? ??? ???? ????? ??????? Bitcoin Lightning ??????? ??? API ?? 3 ???? ?? ????? ???. ???? ????? ??????. ???? ?????. ???? ???????. ???? ?? ???? ??????. ??? ??????.
npm install l402-kit   # TypeScript / Express
pip install l402kit    # Python / FastAPI / Flask
go get github.com/shinydapps/l402-kit/go@v1.10.0  # Go / net/http
cargo add l402kit       # Rust / axum

??????? ???? ?????

  • Stripe: ???? ?????? $0.30 ??? ?????? � ??? ???? ????????? ???????
  • ??????????: ?????????? ???????? ?????? ?????????? ????????
  • ????? ?????? ?????????: ?? ??????? ?????? ?????? � ?? ?????? ??? ???? API
l402-kit ?? ?????? ??????: ????? ??? ??????? ??? Lightning Network? ??????? ?? ??? ?? ?????? ???????? ???? ????.

??? ???

  • ????? API � ????? ?????? ??? ??????? ????? ?? ???????? ??????
  • ???? ????? ?????? ????????? � ??????? ?????? ????????
  • ???????? ???? Stripe � Bitcoin ?? ???? ??

????? ?????? � TypeScript

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

const app = express();

app.get("/premium", l402({
  priceSats: 100,                           // ~$0.06 ??? ???
  lightning: new AlbyProvider(process.env.ALBY_TOKEN!, process.env.ALBY_HUB_URL!),    // ????? ??????? � 0% ????
}), (_req, res) => {
  res.json({ data: "?? ????? ?????." });
});

app.listen(3000);

????? ?????? � Python

from fastapi import FastAPI, Request
from l402kit import l402_required

app = FastAPI()

@app.get("/premium")
@l402_required(
    price_sats=100,
    lightning=ManagedProvider.from_address("you@blink.sv"),
)
async def premium(request: Request):
    return {"data": "?? ????? ?????."}

????? ????

curl http://localhost:3000/premium
# ? {"error":"Payment Required","priceSats":100,"invoice":"lnbc..."}

???? ????

?? ????? ??? API ????? ???? 5 ?????