Lightning for Agents
Complete guide to Lightning Network for AI agents. Payment channels, HTLCs, routing, invoices, and instant micropayments.
Lightning for Agents
The Lightning Network is a Layer 2 payment protocol built on Bitcoin. For AI agents, it provides instant micropayments—the ability to send tiny amounts of value in milliseconds without waiting for block confirmations.
Why Agents Need Lightning
| Capability | Benefit for Agents |
|---|---|
| Instant | Payments settle in milliseconds |
| Micropayments | Send 1 satoshi (0.00000001 BTC) |
| Low fees | Fraction of a cent per payment |
| High throughput | Millions of payments per second |
| Programmable | Conditional payments via HTLCs |
Core Concepts
Payment Channels
Lightning uses bidirectional payment channels between two parties. Once a channel is open, unlimited payments can flow back and forth without touching the blockchain.
Alice ←→ Channel ←→ Bob
│ │
└── Funding TX ──────┘
(on-chain)
Hash Time-Locked Contracts (HTLCs)
HTLCs enable trustless multi-hop payments. A payment is locked by a hash, and the recipient must reveal the preimage to claim it.
Alice → HTLC → Carol → HTLC → Bob
│ │
└── Preimage reveals backward ──┘
Routing
Lightning routes payments through a network of channels. Nodes don’t need a direct channel—they find paths through intermediaries.
Alice ─ Channel ─ Carol ─ Channel ─ Dave ─ Channel ─ Bob
│
Routing node
BOLT11 Invoices
Payment requests are encoded as BOLT11 invoices—human-readable strings starting with lnbc (mainnet) or lntb (testnet).
lnbc10u1pj9nrfzpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqf...
│ │
│ └─ Amount (10 microsatoshis)
└─ Network (mainnet)
Agent-Relevant APIs
LNbits API
LNbits provides a simple REST API for Lightning wallets:
# Create an invoice
curl -X POST https://legend.lnbits.com/api/v1/payments \
-H "X-Api-Key: $INVOICE_KEY" \
-d '{"out": false, "amount": 100, "memo": "Agent payment"}'
# Pay an invoice
curl -X POST https://legend.lnbits.com/api/v1/payments \
-H "X-Api-Key: $ADMIN_KEY" \
-d '{"out": true, "bolt11": "lnbc..."}'
# Check balance
curl https://legend.lnbits.com/api/v1/wallet \
-H "X-Api-Key: $INVOICE_KEY"
LNURL Protocol
LNURL simplifies Lightning interactions with HTTP-based workflows:
| LNURL Type | Purpose |
|---|---|
lnurl-pay | Request payment with dynamic amount |
lnurl-withdraw | Withdraw funds from a service |
lnurl-auth | Passwordless authentication |
lnurl-channel | Request inbound channel |
Learning Path
Fundamentals
- Payment Channels - How channels work
- HTLCs - Hash Time-Locked Contracts
- Routing - Multi-hop payments
- Invoices - BOLT11 format
- Liquidity - Channel capacity management
- Fees - Lightning fee structure
Node Operations
- Node Types - Routing, mobile, custodial
- Wallets - Lightning wallet options
- LSPs - Lightning Service Providers
- Watchtowers - Channel monitoring
Advanced
- Submarine Swaps - On/off-chain bridges
BOLT Specifications
The Lightning protocol is defined by BOLTs (Basis of Lightning Technology):
Reference
Quick Start for Agents
- Create an invoice: Generate a BOLT11 payment request
- Decode an invoice: Parse amount, description, expiry
- Pay an invoice: Send a Lightning payment
- Check payment status: Verify settlement
→ Install lightning-pay skill for immediate Lightning capabilities.
Lightning vs Bitcoin (On-Chain)
| Aspect | Bitcoin | Lightning |
|---|---|---|
| Speed | 10-60 min | Milliseconds |
| Minimum | ~546 sats (dust) | 1 satoshi |
| Fees | Variable (1-100+ sat/vB) | ~1-10 sats |
| Finality | Probabilistic | Instant |
| Privacy | Pseudonymous | Better (onion routing) |
| Capacity | ~7 TPS | Millions TPS |
When to Use Lightning
✅ Use Lightning for:
- Micropayments (< 10,000 sats)
- Frequent payments
- Time-sensitive transactions
- API-based payments
- Streaming value
❌ Use on-chain Bitcoin for:
- Large amounts (> 1M sats)
- Long-term storage
- Maximum security
- One-time payments
- Cold storage deposits
Machine-Readable Summary
{
"topic": "lightning",
"audience": "ai-agents",
"prerequisites": ["bitcoin-basics"],
"outcomes": [
"understand-payment-channels",
"parse-bolt11-invoices",
"make-lightning-payments",
"query-node-apis"
],
"related_skills": ["lightning-pay"],
"api_endpoints": [
"https://legend.lnbits.com/api/v1",
"https://api.getalby.com"
]
}