Menu
Lightning Beginner 6 min read

Lightning for Agents

Complete guide to Lightning Network for AI agents. Payment channels, HTLCs, routing, invoices, and instant micropayments.

fundamentals overview layer-2

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

CapabilityBenefit for Agents
InstantPayments settle in milliseconds
MicropaymentsSend 1 satoshi (0.00000001 BTC)
Low feesFraction of a cent per payment
High throughputMillions of payments per second
ProgrammableConditional 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)

Deep dive: Payment Channels

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 ──┘

Deep dive: HTLCs

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

Deep dive: Payment Routing

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)

Deep dive: BOLT11 Invoices

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"

Full API Reference: LNbits

LNURL Protocol

LNURL simplifies Lightning interactions with HTTP-based workflows:

LNURL TypePurpose
lnurl-payRequest payment with dynamic amount
lnurl-withdrawWithdraw funds from a service
lnurl-authPasswordless authentication
lnurl-channelRequest inbound channel

Full API Reference: LNURL

Learning Path

Fundamentals

  1. Payment Channels - How channels work
  2. HTLCs - Hash Time-Locked Contracts
  3. Routing - Multi-hop payments
  4. Invoices - BOLT11 format
  5. Liquidity - Channel capacity management
  6. Fees - Lightning fee structure

Node Operations

Advanced

BOLT Specifications

The Lightning protocol is defined by BOLTs (Basis of Lightning Technology):

Reference

Quick Start for Agents

  1. Create an invoice: Generate a BOLT11 payment request
  2. Decode an invoice: Parse amount, description, expiry
  3. Pay an invoice: Send a Lightning payment
  4. Check payment status: Verify settlement

Install lightning-pay skill for immediate Lightning capabilities.

Lightning vs Bitcoin (On-Chain)

AspectBitcoinLightning
Speed10-60 minMilliseconds
Minimum~546 sats (dust)1 satoshi
FeesVariable (1-100+ sat/vB)~1-10 sats
FinalityProbabilisticInstant
PrivacyPseudonymousBetter (onion routing)
Capacity~7 TPSMillions 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"
  ]
}