Lightning payment flow

  1. Request a product endpoint. HTTP 402 returns a BOLT11 invoice and payment hash.
  2. Pay the invoice using a mainnet Lightning wallet.
  3. Get the payment preimage from the wallet.
  4. Retry once with both proof headers.

curl

curl -i https://YOUR-WORKER/api/data
curl -H "X-Payment-Hash: HASH" -H "X-Payment-Preimage: PREIMAGE" https://YOUR-WORKER/api/data

Python

import requests
r = requests.get(url)
challenge = r.json()
# Pay challenge["payment_request"] before continuing.
data = requests.get(url, headers={"X-Payment-Hash": challenge["payment_hash"], "X-Payment-Preimage": preimage}).json()

JavaScript

const challenge = await (await fetch(url)).json();
// Pay challenge.payment_request before continuing.
const response = await fetch(url, {headers: {"X-Payment-Hash": challenge.payment_hash, "X-Payment-Preimage": preimage}});

Important: invoices are mainnet, preimages are one-time receipts, and expired challenges require a new invoice.