Menu

Explorer & Settings

Tempo Explorer Submit Project
Back to all projects
X

x402-stellar-channels

by marcelosalloum · Updated Mar 21, 2026

Payment channels for x402 on Stellar Soroban — zero-latency off-chain payments for AI agents

1
Stars
3
Forks
Rust
Language
Mar 17, 2026
Created

In the AI payments ecosystem

x402-stellar-channels is an early-stage Rust project in the AI payments / x402 ecosystem. It currently has 1 GitHub stars and 3 forks.

README.md View on GitHub →

x402 Stellar Channels

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.


The Problem

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.

The Solution

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)

Benchmark

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).


Prerequisites

  • Rust + wasm32-unknown-unknown target:
    rustup target add wasm32-unknown-unknown
    
  • Stellar CLI:
    cargo install stellar-cli --features opt
    
  • Node.js 22+ and pnpm

Quick Start

# 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

How It Works

Off-chain State

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.

Soroban Contract

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

Backwards Compatibility

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.

Security Notes

  • Agent exposure is bounded by deposit amount
  • Server holds latest counter-signed state; can initiate dispute if agent vanishes
  • Observation window (~42 min) protects against old-state submission attacks
  • On-chain settlement reveals total payment flow (not privacy-preserving)

References

All Rust crates →