⚑Agentic Lightning Commerce

Build AI agents that pay and get paid on Lightning rails β€” sub-cent fees, sub-second settlement, fully programmatic. This is the core payment primitive for machine-to-machine commerce on Bitcoin.

What you'll build

An agent that can:

  1. Accept payments by creating Lightning invoices via Spark

  2. Make payments by paying Lightning invoices programmatically

  3. Call paid APIs that settle over Lightning automatically (MPP)

  4. Manage a continuous commerce loop β€” receive payments, process orders, sweep profits to cold BTC storage

Prerequisites

  • Xverse Agentic Wallet CLI installed (npm i -g @secretkeylabs/xverse-wallet-cli)

  • A funded wallet with BTC on Spark (see Getting Startedarrow-up-right)


Step 1: Fund your Spark balance

Lightning payments require BTC on Spark. If your agent's Spark balance is empty, fund it from Bitcoin L1:

# Check current Spark balance
xverse-wallet spark balance --json

# If empty, deposit from L1 (requires ~30 min for 3 confirmations)
xverse-wallet bitcoin balance --json          # confirm you have native BTC
xverse-wallet spark deposit --amount 0.001 --yes --json

# Wait for confirmations, then claim
xverse-wallet spark claim --json

Tip: If you have BTC on another account, check all accounts first: xverse-wallet portfolio --accounts 0-4 --json. You can pay from a specific account using -a <index>.

Step 2: Accept payments β€” create Lightning invoices

Your agent acts as a merchant and generates invoices for incoming payments:

This returns a BOLT11 invoice string that any Lightning-enabled wallet or agent can pay. The amount is in satoshis.

Example agent loop β€” accept and process orders:

Step 3: Make payments β€” pay Lightning invoices

Your agent pays another service or merchant:

The agent can pay any valid BOLT11 invoice β€” from another Xverse wallet, a BTCPay Server merchant, a Lightning-enabled API, or any node on the Lightning Network.

Step 4: Call paid APIs automatically (MPP)

The Machine Payments Protocol (MPP) lets your agent call HTTP APIs that require Lightning payment β€” without any manual payment flow. The CLI handles the full cycle: request β†’ 402 challenge β†’ Lightning payment β†’ credential β†’ response.

Your agent can call any MPP-enabled endpoint the same way β€” data APIs, RPC calls, indexer queries:

Step 5: Treasury management β€” sweep profits

Periodically move accumulated BTC from Spark to cold Bitcoin L1 storage:

Or rebalance into stablecoins:


Putting it all together: continuous commerce loop

Here's the full agent pattern for a Lightning-powered service:

Key numbers

Metric
Value

Settlement time

< 1 second

Transaction fees

Sub-cent (< $0.001)

Invoice creation

Instant

L1 deposit time

~30 min (3 confirmations)

L1 withdrawal time

Depends on speed setting

What's next

Last updated