CPC payment-channel demo using x402 v1. This repo is structured to be handed off as a self-contained monorepo.
contracts/hardhat- CPC contract plan + local chain scaffoldingapps/sequencer- Sequencer service (off-chain channel updates)facilitator/x402-rs- x402-rs fork as a git submoduleapps/service- Paid API demo (returns 402 + CPC scheme)apps/demo-client- One-off TSX client scriptpackages/cpc-x402-sdk- Client helpers (signing + payload helpers)docs- Protocol notes, schema spec, hackathon checklistinfra- Docker compose + env templatesscripts- Seed/run/demo helpers
flowchart LR
Client[Demo client] -->|HTTP| Service[Paid service]
Service -->|/verify / /settle| Facilitator
Facilitator -->|/validate / /settle| Sequencer
Sequencer -->|state| Postgres[(Postgres)]
Service -->|proxy| Nominatim[(Nominatim)]
Client -->|open channel / read| Hardhat[Hardhat chain]
Sequencer -->|RPC read| Hardhat
Facilitator -->|RPC read| Hardhat
sequenceDiagram
participant C as Client
participant S as Service
participant F as Facilitator
participant Q as Sequencer
participant N as Nominatim
C->>S: GET /geocode?query=...
S-->>C: 402 + accepts (CPC)
C->>S: GET /geocode + X-PAYMENT
S->>F: /verify (payload + requirements)
F->>Q: /validate
Q-->>F: ok + channel
F-->>S: verified
S->>F: /settle
F->>Q: /settle (persist update)
Q-->>F: updated channel
F-->>S: settled
S->>N: proxy geocode
N-->>S: results
S-->>C: 200 + X-PAYMENT-RESPONSE
facilitator/x402-rs is a git submodule pointing to the fork:
origin: git@github.com:apetersson/x402-rs.gitupstream: https://github.com/x402-rs/x402-rs.git
Rebase workflow:
cd facilitator/x402-rs
git fetch upstream
git rebase upstream/mainKeep CPC changes isolated to a new scheme module and a small registration change so upstream PRs are clean.
If you have not initialized submodules yet, do this once:
git submodule update --init --recursiveRun the full demo (bootstrap chain, start stack, run client):
./scripts/run-demo.shNotes:
./scripts/run-demo.shrunsinfra/bootstrap-hardhat.sh, starts the docker stack, waits for/health, then runs the client once.- Re-run only the client with
./scripts/run-demo-client.sh. - To reuse an existing
.envwithout redeploying:SKIP_BOOTSTRAP=1 ./scripts/run-demo.sh. - Nominatim may take time to import data; set
SKIP_WAIT=1to skip health checks if needed.
- Start stack: hardhat + facilitator + sequencer + paid service
- Run
apps/demo-clientTSX script - Observe 402 -> pay -> 200
- Scheme ID:
v1-eip155-cpc - Spec:
docs/x402-eip155-cpc-schema.md