Skip to main content

Managed → Soberano (0% fee, full custody)

You started with ManagedProvider because it’s the fastest way to get running. When you’re ready for full custody and 0% fee, the migration is one line.
1

Set up your Lightning provider

Pick a soberano provider. Blink is free, no KYC, instant setup.
# Blink: create account → API Keys → copy key + wallet ID
BLINK_API_KEY=blink_xxxxxxxxxxxxxxxxxxxxxxxx
BLINK_WALLET_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2

Swap the provider — one line

// Before
import { ManagedProvider } from 'l402-kit';
const lightning = ManagedProvider.fromAddress('you@yourdomain.com');

// After
import { BlinkProvider } from 'l402-kit';
const lightning = new BlinkProvider(
  process.env.BLINK_API_KEY!,
  process.env.BLINK_WALLET_ID!,
);
# Before
from l402kit import ManagedProvider
lightning = ManagedProvider.from_address("you@yourdomain.com")

# After
from l402kit.providers.blink import BlinkProvider
lightning = BlinkProvider(
    api_key=os.environ["BLINK_API_KEY"],
    wallet_id=os.environ["BLINK_WALLET_ID"],
)
Everything else — middleware setup, token verification, endpoint code — stays exactly the same.
3

Deploy

Tokens issued by the managed provider continue to work after migration. Verification is pure crypto (SHA256(preimage) == paymentHash) — it has no dependency on which provider created the invoice.There is no migration window, no downtime, no database to update.
Already-paid tokens issued under ManagedProvider remain valid after switching providers. The macaroon only contains a hash and an expiry — no provider-specific data.

Switch between soberano providers

Same pattern — swap the provider instance, nothing else changes.
// Blink → LNbits
import { LNbitsProvider } from 'l402-kit';
const lightning = new LNbitsProvider(
  process.env.LNBITS_KEY!,
  process.env.LNBITS_URL ?? 'https://legend.lnbits.com',
);

// Blink → OpenNode
import { OpenNodeProvider } from 'l402-kit';
const lightning = new OpenNodeProvider(process.env.OPENNODE_KEY!, false);

v1.x → v1.8 (current)

No breaking changes. The SDK is additive — new providers, new agent utilities, new replay adapters. Upgrade with:
npm install l402-kit@latest
pip install --upgrade l402kit
cargo update l402kit
go get github.com/shinydapps/l402-kit/go@latest
If you pinned a specific version, check the changelog for what’s new.

Framework migration

Express → Fastify

// Express
app.get('/api', l402({ priceSats: 10, lightning }), handler);

// Fastify
import { l402Fastify } from 'l402-kit/fastify';

fastify.get('/api', {
  preHandler: l402Fastify({ priceSats: 10, lightning }),
}, handler);

Express → Hono (Cloudflare Workers)

import { Hono } from 'hono';
import { l402Hono } from 'l402-kit/hono';

const app = new Hono();
app.use('/api/*', l402Hono({ priceSats: 10, lightning }));
app.get('/api/data', (c) => c.json({ data: 'paid' }));

Flask → FastAPI

# Flask
from l402kit.flask import l402_required

@app.route('/api')
@l402_required(price_sats=10, lightning=provider)
def handler():
    return jsonify({'data': 'paid'})

# FastAPI
from l402kit import l402_required

@app.get('/api')
@l402_required(price_sats=10, lightning=provider)
async def handler():
    return {'data': 'paid'}

Replay store migration

In-memory → Supabase

Set environment variables — the middleware auto-detects and switches:
SUPABASE_URL=https://xxx.supabase.co
SUPABASE_ANON_KEY=your_anon_key
Existing in-flight tokens keep working. The Supabase store starts recording from the moment it’s active — there’s no historical data to migrate.

In-memory → Redis

import { Redis } from 'ioredis';
import { RedisReplayAdapter } from 'l402-kit';

const redis = new Redis(process.env.REDIS_URL!);

app.get('/api', l402({
  priceSats: 10,
  lightning,
  replayAdapter: new RedisReplayAdapter(redis),
}), handler);

Providers

All provider options and setup

Production Guide

Deployment checklist