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

# Carteiras

> Conecte Blink ou Alby para que seu agente pague invoices Lightning automaticamente.

## Carteiras suportadas

| Carteira                        | Instalação             |     Autocustódia    | Notas                                |
| ------------------------------- | ---------------------- | :-----------------: | ------------------------------------ |
| [Blink](https://blink.sv)       | integrado              |     ❌ custodial     | Configuração mais fácil, GraphQL API |
| [Alby Hub](https://getalby.com) | integrado              | ✅ opção self-hosted | REST API, suporta Hub próprio        |
| Personalizada                   | interface `L402Wallet` |          ✅          | Traga sua própria carteira           |

***

## BlinkWallet

### Configuração

1. Cadastre-se em [blink.sv](https://blink.sv)
2. Acesse **Dashboard → API Keys** → crie uma chave
3. Copie seu **Wallet ID** do dashboard

```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"],
)
```

### Como funciona

Chama a [Blink GraphQL API](https://api.blink.sv/graphql) com a mutation `lnInvoicePaymentSend`. Retorna o `preImage` da transação liquidada.

***

## AlbyWallet

### Configuração

1. Crie uma conta em [getalby.com](https://getalby.com)
2. Acesse **Settings → Access Tokens** → crie um token com escopo `payments:send`
3. (Opcional) Execute seu próprio [Alby Hub](https://github.com/getAlby/hub) para autocustódia

```bash theme={null}
export ALBY_TOKEN="your-access-token"
# Opcional — necessário apenas para Hub self-hosted:
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 self-hosted
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 self-hosted
wallet = AlbyWallet(
    access_token=os.environ["ALBY_TOKEN"],
    base_url=os.environ.get("ALBY_HUB_URL", "https://api.getalby.com"),
)
```

### Como funciona

Chama `POST /payments/bolt11` na REST API do Alby Hub com um token `Bearer`. Retorna o `payment_preimage` da resposta.

***

## Carteira personalizada

Implemente a interface `L402Wallet` para usar qualquer carteira 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>

A interface exige um único método:

| Método                   | TypeScript                                          | Python                            |
| ------------------------ | --------------------------------------------------- | --------------------------------- |
| Pagar uma invoice BOLT11 | `payInvoice(bolt11): Promise<{ preimage: string }>` | `pay_invoice(bolt11: str) -> str` |

***

## Escolhendo uma carteira

* **Testes / prototipagem** → Blink (custodial, configuração instantânea, plano gratuito)
* **Agente em produção, máximo controle** → Alby Hub self-hosted (não custodial, REST API)
* **Alto volume / taxas baixas** → Phoenix via `L402Wallet` personalizada (não custodial, ACINQ)
* **Empresarial** → LNbits self-hosted via carteira personalizada
