⚡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:
Accept payments by creating Lightning invoices via Spark
Make payments by paying Lightning invoices programmatically
Call paid APIs that settle over Lightning automatically (MPP)
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 Started)
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 --jsonTip: 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
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
Explore the full MPP API catalog to see what paid APIs are available
Explore the Xverse API — every endpoint is MPP-enabled and pays via Lightning at 1 sat per request. See MPP Lightning Payments for the full spec, or run
xverse-wallet pay api --jsonto discover endpoints from the CLI.
Add treasury management patterns for rebalancing and yield
Combine with Starknet trading or Flashnet trading for agents that both pay and trade
Last updated