> ## Documentation Index
> Fetch the complete documentation index at: https://shinydapps-bd9fa40b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Providers

> Two modes — Managed (0.3% flat, no node) or Soberano (0%, your own Lightning node). ManagedProvider, Blink, LNbits, OpenNode, and custom.

## Two modes

| Mode          | Provider          | Fee          | Testnet / Sandbox        | Setup                        |
| ------------- | ----------------- | ------------ | ------------------------ | ---------------------------- |
| **Managed** ⭐ | `ManagedProvider` | 0.3% per sat | ❌ (use mock in tests)    | Lightning address only       |
| **Soberano**  | Blink             | 0%           | ❌ mainnet only           | Free custodial account       |
| **Soberano**  | LNbits            | 0%           | ✅ RegTest / signet       | Self-host or public instance |
| **Soberano**  | OpenNode          | 0%           | ✅ `testMode: true`       | Free sandbox account         |
| **Soberano**  | Alby Hub          | 0%           | ✅ via Hub testnet wallet | Self-custodial cloud node    |
| **Soberano**  | BTCPay            | 0%           | ✅ RegTest support        | Self-hosted node             |
| **Soberano**  | Custom            | 0%           | ✅ whatever you wire up   | Any Lightning backend        |

**Managed mode** — l402kit.com hosts the Lightning node. You add your Lightning address. We forward 99.7% of every sat to you automatically.

**Soberano mode** — You connect your own Lightning wallet/node. 0% fee, full custody, works with any provider.

***

## ManagedProvider (Recommended)

No Lightning node needed. Add your Lightning address and start earning — l402kit.com handles all invoice creation and payment routing.

**Fee:** 0.3% per sat received. 99.7% lands directly in your Lightning wallet. No monthly fee.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { l402, ManagedProvider } from 'l402-kit';
  import express from 'express';

  const app = express();
  const lightning = ManagedProvider.fromAddress('you@yourdomain.com');

  app.get('/premium', l402({ priceSats: 10, lightning }), (req, res) => {
    res.json({ data: 'Payment confirmed ⚡' });
  });

  app.listen(3000);
  // 0.3% fee · no node setup · works immediately
  ```

  ```python Python theme={null}
  from l402kit import l402_required, ManagedProvider
  from fastapi import FastAPI

  app = FastAPI()
  lightning = ManagedProvider.from_address("you@yourdomain.com")

  @app.get("/premium")
  @l402_required(price_sats=10, lightning=lightning)
  async def premium():
      return {"data": "Payment confirmed ⚡"}
  # 0.3% fee · no Lightning node required
  ```

  ```go Go theme={null}
  import (
      "fmt"
      "net/http"
      l402kit "github.com/shinydapps/l402-kit/go"
  )

  func main() {
      provider := l402kit.NewManagedProvider("you@yourdomain.com")
      http.Handle("/premium", l402kit.Middleware(l402kit.Options{
          PriceSats: 10,
          Lightning: provider,
      }, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
          fmt.Fprintln(w, `{"data":"Payment confirmed ⚡"}`)
      })))
      http.ListenAndServe(":8080", nil)
  }
  ```

  ```rust Rust theme={null}
  use axum::{middleware, routing::get, Router};
  use l402kit::{l402_middleware, Options, ManagedProvider};
  use std::sync::Arc;

  #[tokio::main]
  async fn main() {
      let provider = ManagedProvider::new("you@yourdomain.com".into());
      let opts = Arc::new(Options::new(10, provider));
      let app = Router::new()
          .route("/premium", get(|| async { r#"{"data":"Payment confirmed ⚡"}"# }))
          .route_layer(middleware::from_fn_with_state(opts, l402_middleware));
      let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
      axum::serve(listener, app).await.unwrap();
  }
  ```
</CodeGroup>

**How it works:**

1. Your API calls `ManagedProvider.fromAddress("you@domain.com")`
2. When a caller hits your endpoint, l402kit.com creates a Lightning invoice
3. Caller pays → Lightning settles → 99.7% forwarded to your Lightning address instantly
4. Your API verifies the cryptographic proof and returns `200 OK`

<Note>
  The 0.3% routing fee is the only cost. No monthly fee. No account registration. Any Lightning address works (Blink, Phoenix, Alby, Strike, Wallet of Satoshi, etc.).
</Note>

### Trust & availability

**Who runs l402kit.com?** ShinyDapps (open source, MIT). The managed infrastructure runs on Cloudflare Workers — globally distributed, no single server to go down.

**Uptime**: Monitored 24/7 at [stats.uptimerobot.com/57uOzF17jK](https://stats.uptimerobot.com/57uOzF17jK). SLA target: 99.9%.

**What if l402kit.com disappears?** Your verification logic is local — `SHA256(preimage) == paymentHash` runs in your process, zero network calls. Only invoice *creation* touches l402kit.com. If the managed service goes down, switch to any soberano provider in one line:

```typescript theme={null}
// Before (managed)
const lightning = ManagedProvider.fromAddress("you@yourdomain.com");

// After (soberano — 0% fee, full custody)
const lightning = new BlinkProvider(process.env.BLINK_API_KEY!, process.env.BLINK_WALLET_ID!);
```

No other code changes. Already-paid tokens keep working — verification is purely cryptographic.

**Can I self-host the managed layer?** Yes. The full source is on [GitHub](https://github.com/ShinyDapps/l402-kit) under MIT. `cloudflare/` contains the managed API worker — deploy it to your own Cloudflare account in 5 minutes.

***

## Blink (Soberano — 0% fee)

[Blink](https://blink.sv) is a free custodial Bitcoin Lightning wallet with a GraphQL API. No KYC, no monthly fee, instant setup. Use it to run in soberano mode with 0% fee.

<Note>
  **Contingency plan:** Blink is a free service — their pricing can change. If Blink adds fees or limits the API, switch to another soberano provider in one line of code (no other changes required, already-paid tokens keep working). Zero lock-in. Good alternatives: LNbits (self-hosted, 0% forever), OpenNode (commercial SLA), Alby Hub (self-custodial), or BTCPay (fully sovereign).
</Note>

**Get started:**

1. Create account at [dashboard.blink.sv](https://dashboard.blink.sv)
2. Go to **API Keys** → create a new key
3. Copy your **BTC Wallet ID** from the wallet page

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { BlinkProvider } from 'l402-kit';

  const blink = new BlinkProvider(
    process.env.BLINK_API_KEY!,    // blink_xxx...
    process.env.BLINK_WALLET_ID!,  // UUID
  );
  ```

  ```python Python theme={null}
  from l402kit.providers.blink import BlinkProvider

  blink = BlinkProvider(
      api_key=os.environ["BLINK_API_KEY"],
      wallet_id=os.environ["BLINK_WALLET_ID"],
  )
  ```

  ```go Go theme={null}
  import "github.com/shinydapps/l402-kit/go"

  provider := l402kit.NewBlinkProvider(
      os.Getenv("BLINK_API_KEY"),
      os.Getenv("BLINK_WALLET_ID"),
  )
  ```
</CodeGroup>

**Environment variables:**

```bash theme={null}
BLINK_API_KEY=blink_xxxxxxxxxxxxxxxxxxxxxxxx
BLINK_WALLET_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```

***

## LNbits (Soberano — 0% fee)

[LNbits](https://lnbits.com) is an open-source Lightning wallet server. Self-host it or use a public instance.

**Get started:**

1. Set up LNbits (self-host or use legend.lnbits.com)
2. Create a wallet → copy the **Invoice/read key**

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { LNbitsProvider } from 'l402-kit';

  const lnbits = new LNbitsProvider(
    process.env.LNBITS_KEY!,
    process.env.LNBITS_URL ?? 'https://legend.lnbits.com',
  );
  ```

  ```python Python theme={null}
  from l402kit.providers.lnbits import LNbitsProvider

  lnbits = LNbitsProvider(
      api_key=os.environ["LNBITS_KEY"],
      base_url=os.environ.get("LNBITS_URL", "https://legend.lnbits.com"),
  )
  ```
</CodeGroup>

**Environment variables:**

```bash theme={null}
LNBITS_KEY=your-invoice-read-key
LNBITS_URL=https://your-lnbits-instance.com
```

***

## OpenNode (Soberano — 0% fee)

[OpenNode](https://opennode.com) is a Lightning provider with a free sandbox for testing.

**Get started:**

1. Create account at [app.opennode.com](https://app.opennode.com)
2. Go to **Integrations** → **API Keys** → create a key

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { OpenNodeProvider } from 'l402-kit';

  const opennode = new OpenNodeProvider(
    process.env.OPENNODE_KEY!,
    process.env.NODE_ENV !== 'production', // testMode
  );
  ```

  ```python Python theme={null}
  from l402kit.providers.opennode import OpenNodeProvider

  opennode = OpenNodeProvider(
      api_key=os.environ["OPENNODE_KEY"],
      test_mode=os.environ.get("NODE_ENV") != "production",
  )
  ```
</CodeGroup>

***

## Alby Hub (Soberano — 0% fee)

[Alby Hub](https://hub.getalby.com) is a self-custodial Lightning node in the cloud. Your keys, your sats — no custodian.

**Get started:**

1. Create a Hub at [hub.getalby.com](https://hub.getalby.com) (or self-host)
2. Go to **Settings → Access Tokens** → create token with `invoices:create` + `invoices:read` scopes
3. Copy your Hub URL and access token

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { AlbyProvider } from 'l402-kit';

  const alby = new AlbyProvider(
    process.env.ALBY_ACCESS_TOKEN!,  // Hub → Settings → Access Tokens
    process.env.ALBY_HUB_URL!,       // e.g. "https://your-name.getalby.com"
  );
  ```
</CodeGroup>

**Environment variables:**

```bash theme={null}
ALBY_ACCESS_TOKEN=your-alby-access-token
ALBY_HUB_URL=https://your-name.getalby.com
```

***

## BTCPay Server (Soberano — 0% fee)

[BTCPay Server](https://btcpayserver.org) is fully self-sovereign Bitcoin + Lightning. Your node, your keys, zero custody.

**Compatible with:** self-hosted (Umbrel, Start9, VPS) or managed (Voltage, LunaNode).

**Get started:**

1. BTCPay store → **Lightning → Settings**
2. **Account → API Keys** → generate key with scope `btcpay.store.cancreatelightninginvoice`
3. Copy your Store ID from the store URL

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { BTCPayProvider } from 'l402-kit';

  const btcpay = new BTCPayProvider(
    process.env.BTCPAY_URL!,       // e.g. "https://btcpay.yourdomain.com"
    process.env.BTCPAY_API_KEY!,   // Account → API Keys
    process.env.BTCPAY_STORE_ID!,  // from store URL
  );
  ```
</CodeGroup>

**Environment variables:**

```bash theme={null}
BTCPAY_URL=https://btcpay.yourdomain.com
BTCPAY_API_KEY=your-api-key
BTCPAY_STORE_ID=your-store-id
```

***

## Custom provider (Soberano — 0% fee)

Implement the `LightningProvider` interface to use any Lightning backend:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import type { LightningProvider, Invoice } from 'l402-kit';

  class MyProvider implements LightningProvider {
    async createInvoice(amountSats: number): Promise<Invoice> {
      // Call your Lightning node API
      const result = await myNode.createInvoice(amountSats);
      const macaroon = Buffer.from(
        JSON.stringify({ hash: result.hash, exp: Date.now() + 3_600_000 })
      ).toString('base64');
      return {
        paymentRequest: result.bolt11,
        paymentHash: result.hash,
        macaroon,
        amountSats,
        expiresAt: Date.now() + 3_600_000,
      };
    }

    async checkPayment(paymentHash: string): Promise<boolean> {
      return myNode.isPaid(paymentHash);
    }
  }
  ```

  ```python Python theme={null}
  from l402kit.types import LightningProvider, Invoice
  from datetime import datetime, timedelta
  import base64, json

  class MyProvider(LightningProvider):
      async def create_invoice(self, amount_sats: int) -> Invoice:
          result = await my_node.create_invoice(amount_sats)
          exp = int((datetime.now() + timedelta(hours=1)).timestamp() * 1000)
          macaroon = base64.b64encode(
              json.dumps({"hash": result.hash, "exp": exp}).encode()
          ).decode()
          return Invoice(
              payment_request=result.bolt11,
              payment_hash=result.hash,
              macaroon=macaroon,
              amount_sats=amount_sats,
              expires_at=exp,
          )

      async def check_payment(self, payment_hash: str) -> bool:
          return await my_node.is_paid(payment_hash)
  ```
</CodeGroup>
