x402 State Channel Demo

Real USDC purchases of generative art on Stellar testnet. Every image on the left is a paid request to a live Cloudflare Worker — verified by real ed25519 cryptography, settled by a real Soroban smart contract.

How it works

Channel side (left) — everything is real

  1. Open channel — A real Soroban transaction deposits USDC into an on-chain escrow contract. A fee-bump relayer pays the XLM gas so the agent spends zero XLM. You can verify this tx on stellar.expert.
  2. Pre-sign states — The agent pre-signs N ed25519 payment states offline (channelId || iteration || balances). Each signature authorizes one more unit of payment to the server. No network calls.
  3. Purchase images — Each request hits the live NFT service at x402-nft-service.sdf-ecosystem.workers.dev with a signed channel payment header. The Cloudflare Worker verifies the ed25519 signature (~microseconds, no blockchain), generates the art, counter-signs the state, and returns a real SVG. Every image you see was paid for.
  4. Close channel — A second real Soroban transaction submits the final mutually-signed state. The contract verifies both signatures and distributes the USDC: unused deposit back to the agent, earned amount to the merchant. Again, relayer pays gas.

Traditional side (right) — real Stellar speed

Standard x402 requires 1 on-chain transaction per API call. Each image waits ~5 seconds for a Stellar ledger close before it can settle. This side runs at that real speed — you'll see one image every ~5 seconds. For 100 images that's over 8 minutes. The placeholder art is local but the timing is honest.

Why channels win

The on-chain cost is fixed at 2 transactions regardless of how many images you buy. The per-image cost is just an ed25519 signature verification — pure math, no network, no gas. At 100 images, that's a ~50x speedup. At 1,000, it's ~500x.

Channel: real USDC • real signatures • real art Traditional: ~5s per image (real Stellar ledger close time)
Channel x402 (LIVE) 2 on-chain txs
Purchased
0
Elapsed
0.0 s
Rate
— img/s
On-chain Txs
2
Waiting…
🐢 Traditional x402 1 tx per image
Purchased
0
Elapsed
0.0 s
Rate
— img/s
On-chain Txs
0
Waiting…

Results

Channel Total
open + sign + purchase + close
Traditional Total
1 on-chain tx per image @ ~5s each
Speedup
channel vs traditional