Payment channels for x402 on Stellar Soroban — zero-latency off-chain payments for AI agents
x402-stellar-channels is an early-stage Rust project in the AI payments / x402 ecosystem. It currently has 1 GitHub stars and 3 forks.
A proof-of-concept unidirectional payment channel for x402 on Stellar, using Soroban smart contracts. Reduces per-request payment overhead from ~5s to <10ms after channel open.
x402 requires an on-chain transaction per API call. For an AI agent making 20 calls to a paid API, that's ~100 seconds of payment latency — before the actual work even begins.
Open a channel once (1 on-chain tx), pay per request with a local ed25519 signature (no chain), close once (1 on-chain tx). N calls = 2 transactions total.
SETUP (once, ~7s): Agent → Facilitator → Stellar: open_channel(deposit=1 USDC)
EACH REQUEST (~10ms): Agent → Server: GET /data + X-Payment: {signed state}
Server verifies signature locally → 200 OK
TEARDOWN (once, ~5s): Agent → Facilitator → Stellar: close_channel(finalState)
| Mode | 20 calls total | Per-call avg |
|---|---|---|
| Vanilla x402 | ~102s | ~5,100ms |
| Channel x402 | ~12s (incl. open+close) | ~10ms |
| Speedup | 8.8x | 509x |
Break-even: 3 calls (channels win from the 3rd call onward).
wasm32-unknown-unknown target:rustup target add wasm32-unknown-unknown
cargo install stellar-cli --features opt
# Install TypeScript deps and deploy to testnet (creates .env.testnet)
cd demo
pnpm install
pnpm setup:testnet
# Terminal 1: facilitator
pnpm facilitator
# Terminal 2: API server
pnpm api
# Terminal 3: benchmark
pnpm benchmark
Each API request includes a signed 72-byte state in the X-Payment header:
{
"scheme": "channel",
"channelId": "abc...",
"iteration": 42,
"agentBalance": "9580000",
"serverBalance": "420000",
"agentSig": "a3f1..."
}
The server verifies the ed25519 signature locally (microseconds, no network) and responds with its counter-signature. Both parties accumulate the latest mutual state, which can be submitted on-chain at any time.
The contract manages channel lifecycle and dispute resolution:
| Function | Description |
|---|---|
open_channel |
Agent deposits USDC into escrow; 1 on-chain tx |
close_channel |
Both parties sign final state; immediate settlement |
initiate_dispute |
Either party submits their last-known state; 42min window starts |
resolve_dispute |
Counter-party presents higher-iteration mutual state; window resets |
finalize_dispute |
After window expires, highest-iteration state wins |
keep_alive |
Extends Soroban storage TTL for long-running channels |
The channel scheme is additive — servers advertise both exact (vanilla x402) and channel in the 402 response. Clients that don't support channels fall back automatically.
Agent behavior that compiles
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
x402 payments in Rust: verify, settle, and monitor payments over HTTP 402 flows
Context-aware agentic LLM gateway & router that optimize your agentic workflows with every runs, works with any harnesses, any models, any workflows.
Production-ready x402 facilitator server.
Rust SDK for the x402 payment protocol.