ecosystem: add x402s — state channel payments for agents and APIs#1907
Open
pr0toshi wants to merge 1 commit intox402-foundation:mainfrom
Open
ecosystem: add x402s — state channel payments for agents and APIs#1907pr0toshi wants to merge 1 commit intox402-foundation:mainfrom
pr0toshi wants to merge 1 commit intox402-foundation:mainfrom
Conversation
🟡 Heimdall Review Status
|
|
Someone is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
Adds x402s to the ecosystem page under Infrastructure & Tooling, along with the statechannel scheme spec docs. x402s is the reference implementation of the statechannel payment scheme for x402. Agents open a funded channel once, pay thousands of API calls off-chain via signed state updates, and settle on-chain only when the channel closes. Components: - X402StateChannel.sol — on-chain dispute contract (deterministic CREATE2) - Hub server — quote/issue/settlement workflows with configurable fees - Agent SDK + CLI — discover offers, open channels, make paid API calls - Payee server template — protect any API route with 402 + statechannel - Challenge watcher — monitors and disputes stale on-chain closes Ecosystem entry: - typescript/site/app/ecosystem/partners-data/x402s/metadata.json - typescript/site/public/logos/x402s.png Spec docs: - specs/schemes/statechannel/scheme_statechannel.md — scheme overview - specs/schemes/statechannel/scheme_statechannel_evm.md — EVM implementation - docs/extensions/state-channels.mdx — user-facing docs - docs/docs.json — nav entry Reference implementation: github.com/Keychain-Inc/x402s
7314a72 to
bf5cbfd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds x402s to the ecosystem page under Infrastructure & Tooling, along with the statechannel scheme spec docs.
x402s is the reference implementation of the statechannel payment scheme for x402. Agents open a funded channel once, pay thousands of API calls off-chain via signed state updates, and settle on-chain only when the channel closes.
Reference implementation: github.com/Keychain-Inc/x402s
Description
Adds x402s to the ecosystem page under Infrastructure & Tooling, along with the statechannel scheme spec docs.
x402s is the reference implementation of the statechannel payment scheme for x402. Agents open a funded channel once, pay thousands of API calls off-chain via signed state updates, and settle on-chain only when the channel closes.
Components:
X402StateChannel.sol — on-chain dispute contract (deterministic CREATE2)
Hub server — quote/issue/settlement workflows with configurable fees
Agent SDK + CLI — discover offers, open channels, make paid API calls
Payee server template — protect any API route with 402 + statechannel offers
Challenge watcher — monitors and disputes stale on-chain closes
Ecosystem entry:
typescript/site/app/ecosystem/partners-data/x402s/metadata.json
typescript/site/public/logos/x402s.png
Spec docs:
specs/schemes/statechannel/scheme_statechannel.md — scheme overview, trust model, security requirements
specs/schemes/statechannel/scheme_statechannel_evm.md — EVM implementation: EIP-712 signing, contract interface, verification, settlement, streaming
docs/extensions/state-channels.mdx — user-facing docs page
docs/docs.json — nav entry (+1 line)
Problem
The
exactscheme settles every payment onchain. For the emerging class of agent-to-API micropayments with thousands of sub-cent calls per session across dozens of services, this creates three compounding problems:1. Gas exceeds payment value. A $0.0001 API call costs $0.001+ in L2 gas. The payment infrastructure costs 10x the payment itself. For high-frequency agent workflows (tool calls, data feeds, LLM token billing), this makes programmatic micropayments uneconomical.
2. Latency per request. Each call waits for onchain confirmation, adding seconds to every API roundtrip. Agents making 100+ calls per session spend more time waiting for settlement than consuming the service.
3. Chain congestion from volume. An agent ecosystem generating millions of daily API calls would create unsustainable transaction volume, even on L2s. Each call is a separate on-chain transaction.
The
uptoscheme (proposed by Cloudflare) addresses deferred settlement but still requires one settlement transaction per session and introduces a trusted facilitator model with deferred authorization. State channels eliminate per-session settlement entirely while maintaining cryptographic payment proofs on every request.Proposed solution:
statechannelschemeA new x402 payment scheme where:
Comparison with existing schemes
exactuptostatechannelWhy existing schemes don't suffice
exactrequires one on-chain transaction per payment. Unsuitable for high-frequency micropayments.uptobatches settlement but requires a new authorization per session and trusts the facilitator to settle correctly. The client cannot cryptographically prove each individual payment was authorized, only the aggregate.statechannelproduces a cryptographic proof (signed state update) for every individual payment, verifiable on-chain if disputed. The channel persists across sessions. One deposit funds thousands of payments across many payees (hub route) or a single payee (direct route).Design: single scheme identifier with route modes
{ "scheme": "statechannel", "network": "eip155:8453", "amount": "1000000", "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "payTo": "pay.eth", "maxTimeoutSeconds": 60, "extensions": { "statechannel": { "info": { "route": "hub", "hubEndpoint": "https://pay.eth/.well-known/x402", "mode": "proxy_hold", "feeModel": { "base": "10", "bps": 30 } }, "schema": { "type": "object" } } } }Two route modes under one scheme identifier, declared in
extensions.statechannel.info.route:hubdirectBoth modes preserve standard x402
402challenge-and-retry semantics. Payees return402 Payment Requiredwith statechannel offers; clients construct payment proofs and retry with thePAYMENT-SIGNATUREheader.Servers can offer both routes in the same
accepts[]array, and SHOULD offer a fallbackexactscheme during rollout for clients that don't support state channels.Technical architecture
Payment flow (hub route)
402with statechannel offers.amount + fee.PAYMENT-SIGNATUREheader.Total on-chain transactions for 1,000 API calls: 1 (the original channel open). Compare to
exact: 1,000.EIP-712 typed data signing
All state updates are signed as EIP-712 typed data, bound to the specific chain and contract:
Key constraint:
balA + balBMUST always equal the channel's on-chaintotalBalance. The contract enforces this invariant on every cooperative close, challenge, and rebalance.Smart contract interface
The
X402StateChannelcontract is the on-chain adjudicator. Deployed via CREATE2 at the same canonical address (0x07ECA6701062Db12eDD04bEa391eD226C95aaD4b) on all supported EVM chains.openChannel(participantB, asset, amount, challengePeriodSec, channelExpiry, salt)deposit(channelId, amount)cooperativeClose(state, sigA, sigB)startClose(state, sigCounterparty)challenge(newerState, sigCounterparty)finalizeClose(channelId)rebalance(fromState, toChannelId, amount, sigCounterparty)Channel ID derivation (deterministic, collision-free):
Verification logic
Hub route (payee-side):
PAYMENT-SIGNATUREheaderticket.sigrecovers to known hub addresschannelProof.stateHashmatches hash of submitted channel stateticket.expiryis in the futureticket.payeematches own addressticket.amount≥ required paymentticket.assetmatches required assetpaymentIdnot previously consumed (replay protection)GET /v1/payments/{paymentId}Direct route (payee-side):
sigAvia EIP-712; must matchparticipantAstateNoncemust strictly exceed last accepted noncebalA + balBmust equal on-chaintotalBalancepaymentIdnot previously consumedHub internal validation (on ticket issue):
participantAbalA + balB == totalBalanceprev.balA - current.balA == quote.totalDebitmaxFeefrom quote requestcontextHashbinds payment to specific{payee, resource, invoiceId, paymentId, amount, asset}Settlement
Cooperative close (preferred): Both parties sign the final state. Either party submits one transaction. Contract verifies both EIP-712 signatures, transfers
balAto A andbalBto B. No challenge period.Unilateral close + challenge: If one party is unresponsive:
Hub rebalancing: When an agent pays via the hub, the hub credits the payee off-chain. To keep on-chain accounting accurate, the hub can atomically move funds between channels via
rebalance(), deducting from the agent-hub channel and crediting the hub-payee channel in a single transaction.Streaming extension
For metered billing (pay-per-second, pay-per-token):
{ "extensions": { "statechannel": { "info": { "route": "hub", "stream": { "amount": "100000000000", "t": 5 }, "hubEndpoint": "https://pay.eth/.well-known/x402" } } } }The client signs a new state update every
tseconds, debitingstream.amount. No polling, no webhooks, just a continuous stream of signed state updates.Trust model
Hub route
maxFee. The payer never authorizes more than they explicitly sign. The hub cannot move funds beyond the co-signed state.Direct route
Alignment with x402 principles
exact(where the facilitator broadcasts the transaction); the facilitator here cannot even broadcast a transaction that exceeds the signed authorization.402flow is identical from the payee's perspective, just a differentschemevalue and payment proof format.Reference implementation
[github.com/Keychain-Inc/x402s](https://github.com/Keychain-Inc/x402s): fully working, MIT licensed.
contracts/X402StateChannel.solnode/scp-hub/server.jsnode/scp-agent/agent-client.jsnode/scp-demo/payee-server.jsnode/scp-demo/chat-server.jsnode/scp-demo/weather-api/scp-pay/index.htmltest/Live on Base and Sepolia. Canonical contract:
0x07ECA6701062Db12eDD04bEa391eD226C95aaD4bSpec docs (ready for review)
specs/schemes/statechannel/scheme_statechannel.md: scheme overview, trust model, security requirementsspecs/schemes/statechannel/scheme_statechannel_evm.md: EVM implementation: EIP-712 signing, contract interface, verification logic, settlement, streaming, fee model (609 lines)docs/extensions/state-channels.mdx: user-facing docs pageThese follow the format established by
specs/schemes/exact/scheme_exact_evm.mdand are submitted in PR #1907.What this does NOT require
extensionsobject, standardschemefield, standardPAYMENT-SIGNATUREheaderX402StateChannelcontract is a standalone adjudicatorstatechannelalongsideexactin the sameaccepts[]arrayOpen questions
Reference implementation: github.com/Keychain-Inc/x402s
Tests
No runtime code changes — this PR adds only static content (spec markdown, docs page, ecosystem metadata, logo). Verified:
docs.json is valid JSON after nav entry insertion
All file paths match the existing ecosystem and specs directory conventions
Logo is PNG, metadata.json matches the schema used by other ecosystem entries
Checklist