> ## 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

> दो modes — Managed (0.3% flat, कोई node नहीं) या Soberano (0%, आपका खुद का Lightning node). ManagedProvider, Blink, LNbits, OpenNode, और custom.

## दो modes

| Mode          | Provider          | Fee            | Testnet / Sandbox                 | Setup                        |
| ------------- | ----------------- | -------------- | --------------------------------- | ---------------------------- |
| **Managed** ⭐ | `ManagedProvider` | 0.3% प्रति sat | ❌ (tests में mock उपयोग करें)     | केवल Lightning address       |
| **Soberano**  | Blink             | 0%             | ❌ केवल mainnet                    | Free custodial account       |
| **Soberano**  | LNbits            | 0%             | ✅ RegTest / signet                | Self-host या public instance |
| **Soberano**  | OpenNode          | 0%             | ✅ `testMode: true`                | Free sandbox account         |
| **Soberano**  | Alby Hub          | 0%             | ✅ Hub testnet wallet के माध्यम से | Self-custodial cloud node    |
| **Soberano**  | BTCPay            | 0%             | ✅ RegTest support                 | Self-hosted node             |
| **Soberano**  | Custom            | 0%             | ✅ जो भी आप wire up करें           | कोई भी Lightning backend     |

**Managed mode** — l402kit.com Lightning node host करता है। आप अपना Lightning address जोड़ें। हम हर sat का 99.7% आपको automatically forward करते हैं।

**Soberano mode** — आप अपना खुद का Lightning wallet/node connect करें। 0% fee, full custody, किसी भी provider के साथ काम करता है।

***

## ManagedProvider (अनुशंसित)

कोई Lightning node की जरूरत नहीं। अपना Lightning address जोड़ें और earning शुरू करें — l402kit.com सभी invoice creation और payment routing संभालता है।

**Fee:** प्रति sat received पर 0.3%। 99.7% सीधे आपके Lightning wallet में जाता है। कोई 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>

**यह कैसे काम करता है:**

1. आपका API `ManagedProvider.fromAddress("you@domain.com")` call करता है
2. जब कोई caller आपके endpoint को hit करता है, l402kit.com एक Lightning invoice बनाता है
3. Caller payment करता है → Lightning settle होता है → 99.7% आपके Lightning address पर instantly forward होता है
4. आपका API cryptographic proof verify करता है और `200 OK` return करता है

<Note>
  0.3% routing fee ही एकमात्र cost है। कोई monthly fee नहीं। कोई account registration नहीं। कोई भी Lightning address काम करता है (Blink, Phoenix, Alby, Strike, Wallet of Satoshi, आदि)।
</Note>

### Trust और availability

**l402kit.com कौन चलाता है?** ShinyDapps (open source, MIT)। Managed infrastructure Cloudflare Workers पर चलता है — globally distributed, कोई single server down नहीं होता।

**Uptime**: [stats.uptimerobot.com/57uOzF17jK](https://stats.uptimerobot.com/57uOzF17jK) पर 24/7 monitor किया जाता है। SLA target: 99.9%।

**अगर l402kit.com बंद हो जाए?** आपका verification logic local है — `SHA256(preimage) == paymentHash` आपके process में चलता है, zero network calls। केवल invoice *creation* l402kit.com को touch करता है। अगर managed service down हो जाए, तो एक line में किसी भी soberano provider पर switch करें:

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

// बाद में (soberano — 0% fee, full custody)
const lightning = new BlinkProvider(process.env.BLINK_API_KEY!, process.env.BLINK_WALLET_ID!);
```

कोई अन्य code changes नहीं। पहले से paid tokens काम करते रहेंगे — verification purely cryptographic है।

**क्या मैं managed layer को self-host कर सकता हूं?** हाँ। Full source MIT license के तहत [GitHub](https://github.com/ShinyDapps/l402-kit) पर है। `cloudflare/` में managed API worker है — इसे 5 मिनट में अपने Cloudflare account पर deploy करें।

***

## Blink (Soberano — 0% fee)

[Blink](https://blink.sv) एक free custodial Bitcoin Lightning wallet है जिसमें GraphQL API है। कोई KYC नहीं, कोई monthly fee नहीं, instant setup। इसे soberano mode में 0% fee के साथ उपयोग करें।

<Note>
  **Contingency plan:** Blink एक free service है — उनकी pricing बदल सकती है। अगर Blink fees add करे या API limit करे, तो एक line of code में दूसरे soberano provider पर switch करें (कोई अन्य changes नहीं, पहले से paid tokens काम करते रहेंगे)। Zero lock-in। अच्छे alternatives: LNbits (self-hosted, 0% हमेशा), OpenNode (commercial SLA), Alby Hub (self-custodial), या BTCPay (fully sovereign)।
</Note>

**शुरू करें:**

1. [dashboard.blink.sv](https://dashboard.blink.sv) पर account बनाएं
2. **API Keys** पर जाएं → एक नई key बनाएं
3. Wallet page से अपना **BTC Wallet ID** copy करें

<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) एक open-source Lightning wallet server है। इसे self-host करें या public instance उपयोग करें।

**शुरू करें:**

1. LNbits setup करें (self-host या legend.lnbits.com उपयोग करें)
2. एक wallet बनाएं → **Invoice/read key** copy करें

<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) एक Lightning provider है जिसमें testing के लिए free sandbox है।

**शुरू करें:**

1. [app.opennode.com](https://app.opennode.com) पर account बनाएं
2. **Integrations** → **API Keys** पर जाएं → एक 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) cloud में एक self-custodial Lightning node है। आपकी keys, आपके sats — कोई custodian नहीं।

**शुरू करें:**

1. [hub.getalby.com](https://hub.getalby.com) पर एक Hub बनाएं (या self-host करें)
2. **Settings → Access Tokens** पर जाएं → `invoices:create` + `invoices:read` scopes के साथ token बनाएं
3. अपना Hub URL और access token copy करें

<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) fully self-sovereign Bitcoin + Lightning है। आपका node, आपकी keys, zero custody।

**इनके साथ compatible:** self-hosted (Umbrel, Start9, VPS) या managed (Voltage, LunaNode)।

**शुरू करें:**

1. BTCPay store → **Lightning → Settings**
2. **Account → API Keys** → `btcpay.store.cancreatelightninginvoice` scope के साथ key generate करें
3. Store URL से अपना Store ID copy करें

<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!,  // 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)

किसी भी Lightning backend का उपयोग करने के लिए `LightningProvider` interface implement करें:

<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>
