Skip to content
ln.bot

SDKs

Native SDK libraries for ln.bot — TypeScript, Python, Go, Rust, and C#. Plus L402 paywall middleware for Express.js and ASP.NET Core.

Updated View as Markdown

Native libraries for TypeScript, Python, Go, Rust, and C#.

TypeScript

bash
npm install @lnbot/sdk
typescript
import { LnBot } from "@lnbot/sdk"

const ln = new LnBot({
  apiKey: process.env.LNBOT_API_KEY!
})

// Create an invoice
const inv = await ln.invoices.create({
  amount: 1000,
  memo: "AI task payment"
})

// Pay another agent
const pay = await ln.payments.create({
  target: "r7vq3np@ln.bot",
  amount: 500
})

// Check balance
const wallet = await ln.wallets.current()
console.log(wallet.available)

Python

bash
pip install lnbot
python
from lnbot import LnBot

ln = LnBot(api_key="key__...")

# Create an invoice
inv = ln.invoices.create(
    amount=1000,
    memo="AI task payment"
)

# Pay another agent
pay = ln.payments.create(
    target="r7vq3np@ln.bot",
    amount=500
)

# Check balance
wallet = ln.wallets.current()
print(wallet.available)

Go

bash
go get github.com/lnbotdev/go-sdk
go
package main

import (
    "context"
    "fmt"
    lnbot "github.com/lnbotdev/go-sdk"
)

func main() {
    ln := lnbot.New("key__...")
    ctx := context.Background()

    // Create an invoice
    inv, _ := ln.Invoices.Create(ctx, &lnbot.CreateInvoiceParams{
        Amount: 1000,
    })

    // Pay another agent
    _, _ = ln.Payments.Create(ctx, &lnbot.CreatePaymentParams{
        Target: "r7vq3np@ln.bot",
        Amount: lnbot.Ptr(int64(500)),
    })

    // Check balance
    w, _ := ln.Wallets.Current(ctx)
    fmt.Println(w.Available)
}

Rust

bash
cargo add lnbot
rust
use lnbot::{LnBot, CreateInvoiceRequest, CreatePaymentRequest};

#[tokio::main]
async fn main() {
    let ln = LnBot::new("key__...");

    // Create an invoice
    let inv = ln.invoices().create(
        &CreateInvoiceRequest::new(1000).memo("AI task")
    ).await.unwrap();

    // Pay another agent
    ln.payments().create(
        &CreatePaymentRequest::new("r7vq3np@ln.bot").amount(500)
    ).await.unwrap();

    // Check balance
    let w = ln.wallets().current().await.unwrap();
    println!("{}", w.available);
}

C#

bash
dotnet add package LnBot
csharp
using LnBot;
using LnBot.Models;

using var client = new LnBotClient("key__...");

// Create an invoice
var inv = await client.Invoices.CreateAsync(new CreateInvoiceRequest
{
    Amount = 1000,
    Memo = "AI task payment"
});

// Pay another agent
var pay = await client.Payments.CreateAsync(new CreatePaymentRequest
{
    Target = "r7vq3np@ln.bot",
    Amount = 500
});

// Check balance
var wallet = await client.Wallets.CurrentAsync();
Console.WriteLine(wallet.Available);

L402 Libraries

Paywall middleware — add Lightning-powered pay-per-request to any API. Built on the L402 API endpoints.

TypeScript — Express.js

bash
npm install @lnbot/l402
typescript
import { l402, LnBot } from "@lnbot/l402"

// Server — paywall a route
app.use("/api/premium", l402.paywall(ln, { price: 10 }))

// Client — auto-pay L402 APIs
const client = l402.client(ln, { maxPrice: 100 })
const data = await client.get("https://api.example.com/premium")

C# — ASP.NET Core

bash
dotnet add package LnBot.L402.AspNetCore
csharp
// Server — paywall a route
using LnBot;  using LnBot.L402;
app.UseL402Paywall("/api/premium", new L402Options { Price = 10 });

// Client — auto-pay L402 APIs via HttpClient
builder.Services.AddHttpClient("paid-apis")
    .AddL402Handler(new L402ClientOptions { MaxPrice = 100 });