Skip to main content

Overview

A Lightning Provider is the service that creates invoices and checks payment status. l402-kit ships with 3 built-in providers and a simple interface for custom ones.
ProviderFree tierSelf-hostedRecommended
Blink✅ Unlimited❌ Custodial✅ Yes
LNbits✅ (self-host)✅ Full controlFor self-hosters
OpenNode✅ Sandbox❌ CustodialSandbox testing

Blink is a free custodial Bitcoin Lightning wallet with a GraphQL API. No KYC, no monthly fee, instant setup. Get started:
  1. Create account at dashboard.blink.sv
  2. Go to API Keys → create a new key
  3. Copy your BTC Wallet ID from the wallet page
import { BlinkProvider } from 'l402-kit';

const blink = new BlinkProvider(
  process.env.BLINK_API_KEY!,    // blink_xxx...
  process.env.BLINK_WALLET_ID!,  // UUID
);
Environment variables:
BLINK_API_KEY=blink_GHRHAIuz...
BLINK_WALLET_ID=9da6b07e-7aaa-44e0-bc96-f1e22610b4d1

LNbits

LNbits 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
import { LNbitsProvider } from 'l402-kit';

const lnbits = new LNbitsProvider(
  process.env.LNBITS_KEY!,
  process.env.LNBITS_URL ?? 'https://legend.lnbits.com',
);
Environment variables:
LNBITS_KEY=your-invoice-read-key
LNBITS_URL=https://your-lnbits-instance.com

OpenNode

OpenNode is a Lightning provider with a free sandbox for testing. Get started:
  1. Create account at app.opennode.com
  2. Go to IntegrationsAPI Keys → create a key
import { OpenNodeProvider } from 'l402-kit';

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

Custom provider

Implement the LightningProvider interface to use any Lightning backend:
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);
  }
}