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

# Portefeuilles

> Connectez Blink ou Alby pour permettre à votre agent de payer des factures Lightning automatiquement.

## Portefeuilles pris en charge

| Portefeuille                    | Installation           |       Auto-garde       | Notes                                     |
| ------------------------------- | ---------------------- | :--------------------: | ----------------------------------------- |
| [Blink](https://blink.sv)       | intégré                |       ❌ custodial      | Configuration la plus simple, API GraphQL |
| [Alby Hub](https://getalby.com) | intégré                | ✅ option auto-hébergée | API REST, supporte son propre Hub         |
| Personnalisé                    | interface `L402Wallet` |            ✅           | Apportez votre propre portefeuille        |

***

## BlinkWallet

### Configuration

1. Inscrivez-vous sur [blink.sv](https://blink.sv)
2. Accédez à **Dashboard → API Keys** → créez une clé
3. Copiez votre **Wallet ID** depuis le tableau de bord

```bash theme={null}
export BLINK_API_KEY="your-api-key"
export BLINK_WALLET_ID="your-wallet-id"
```

### Node.js

```typescript theme={null}
import { BlinkWallet } from "l402-kit";

const wallet = new BlinkWallet(
  process.env.BLINK_API_KEY!,
  process.env.BLINK_WALLET_ID!,
);
```

### Python

```python theme={null}
from l402kit.wallets import BlinkWallet

wallet = BlinkWallet(
    api_key=os.environ["BLINK_API_KEY"],
    wallet_id=os.environ["BLINK_WALLET_ID"],
)
```

### Comment ça fonctionne

Appelle l'[API GraphQL de Blink](https://api.blink.sv/graphql) avec la mutation `lnInvoicePaymentSend`. Retourne le `preImage` de la transaction réglée.

***

## AlbyWallet

### Configuration

1. Créez un compte sur [getalby.com](https://getalby.com)
2. Accédez à **Settings → Access Tokens** → créez un jeton avec la portée `payments:send`
3. (Facultatif) Exécutez votre propre [Alby Hub](https://github.com/getAlby/hub) pour l'auto-garde

```bash theme={null}
export ALBY_TOKEN="your-access-token"
# Facultatif — uniquement nécessaire pour un Hub auto-hébergé :
export ALBY_HUB_URL="https://your-hub.example.com"
```

### Node.js

```typescript theme={null}
import { AlbyWallet } from "l402-kit";

// Alby cloud
const wallet = new AlbyWallet(process.env.ALBY_TOKEN!);

// Hub auto-hébergé
const wallet = new AlbyWallet(
  process.env.ALBY_TOKEN!,
  process.env.ALBY_HUB_URL,  // optional base URL
);
```

### Python

```python theme={null}
from l402kit.wallets import AlbyWallet

# Alby cloud
wallet = AlbyWallet(os.environ["ALBY_TOKEN"])

# Hub auto-hébergé
wallet = AlbyWallet(
    access_token=os.environ["ALBY_TOKEN"],
    base_url=os.environ.get("ALBY_HUB_URL", "https://api.getalby.com"),
)
```

### Comment ça fonctionne

Appelle `POST /payments/bolt11` sur l'API REST d'Alby Hub avec un jeton `Bearer`. Retourne le `payment_preimage` de la réponse.

***

## Portefeuille personnalisé

Implémentez l'interface `L402Wallet` pour utiliser n'importe quel portefeuille Lightning :

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import type { L402Wallet } from "l402-kit";

    class PhoenixWallet implements L402Wallet {
      async payInvoice(bolt11: string): Promise<{ preimage: string }> {
        const res = await fetch("http://localhost:9740/payinvoice", {
          method: "POST",
          body: new URLSearchParams({ invoice: bolt11 }),
        });
        const data = await res.json();
        return { preimage: data.paymentPreimage };
      }
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from l402kit import L402Wallet
    import httpx

    class PhoenixWallet(L402Wallet):
        def pay_invoice(self, bolt11: str) -> str:
            r = httpx.post(
                "http://localhost:9740/payinvoice",
                data={"invoice": bolt11},
            )
            r.raise_for_status()
            return r.json()["paymentPreimage"]
    ```
  </Tab>
</Tabs>

L'interface requiert une seule méthode :

| Méthode                  | TypeScript                                          | Python                            |
| ------------------------ | --------------------------------------------------- | --------------------------------- |
| Payer une facture BOLT11 | `payInvoice(bolt11): Promise<{ preimage: string }>` | `pay_invoice(bolt11: str) -> str` |

***

## Choisir un portefeuille

* **Tests / prototypage** → Blink (custodial, configuration instantanée, offre gratuite)
* **Agent en production, contrôle maximal** → Alby Hub auto-hébergé (non-custodial, API REST)
* **Débit élevé / frais réduits** → Phoenix via `L402Wallet` personnalisé (non-custodial, ACINQ)
* **Entreprise** → LNbits auto-hébergé via un portefeuille personnalisé
