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

# Migration Guide

> Move from Managed to Soberano mode, upgrade between versions, or switch Lightning providers — without downtime.

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

<Steps>
  <Step title="Set up your Lightning provider">
    Pick a soberano provider. [Blink](https://dashboard.blink.sv) is free, no KYC, instant setup.

    ```bash theme={null}
    # Blink: create account → API Keys → copy key + wallet ID
    BLINK_API_KEY=blink_xxxxxxxxxxxxxxxxxxxxxxxx
    BLINK_WALLET_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    ```
  </Step>

  <Step title="Swap the provider — one line">
    ```typescript theme={null}
    // 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!,
    );
    ```

    ```python theme={null}
    # 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.
  </Step>

  <Step title="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.
  </Step>
</Steps>

<Note>
  Already-paid tokens issued under ManagedProvider remain valid after switching providers. The macaroon only contains a hash and an expiry — no provider-specific data.
</Note>

***

## Switch between soberano providers

Same pattern — swap the provider instance, nothing else changes.

```typescript theme={null}
// 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:

```bash theme={null}
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](https://github.com/ShinyDapps/l402-kit/releases) for what's new.

***

## Framework migration

### Express → Fastify

```typescript theme={null}
// 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)

```typescript theme={null}
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

```python theme={null}
# 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:

```bash theme={null}
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

```typescript theme={null}
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);
```

<CardGroup cols={2}>
  <Card title="Providers" icon="plug" href="/providers">
    All provider options and setup
  </Card>

  <Card title="Production Guide" icon="rocket" href="/guides/production">
    Deployment checklist
  </Card>
</CardGroup>
