Flow
- Request
{API}/x/{serviceId}/…. You get HTTP 402 withaccepts[0].scheme = "escrow". - Sign an EIP-3009
ReceiveWithAuthorizationon USDG to the vault. Its nonce is the order id. - Repeat the request with
X-PAYMENT. The server opens the order on-chain, which pulls your USDG into the vault. - The server calls the seller and checks the answer. Pass: the vault pays the seller and you get the response. Fail: the vault refunds you, plus the order's cover from the seller's bond, and you get HTTP 502 with the reason.
- Either way,
X-PAYMENT-RESPONSEcarries a receipt: order id, verdict, latency and both transaction hashes. If nobody posts a verdict, anyone can refund the order one hour after its deadline.
The 402
Signing
EIP-712 domain: { name: "Global Dollar", version: "1", chainId: 4663, verifyingContract: USDG }. Type:
ReceiveWithAuthorization(address from, address to, uint256 value,
uint256 validAfter, uint256 validBefore, bytes32 nonce)
to = vault value = price nonce = orderId
The X-PAYMENT header is base64 of:
{ "x402Version": 1, "scheme": "escrow", "network": "eip155:4663",
"payload": { "signature": "0x…",
"authorization": { "from", "to", "value", "validAfter", "validBefore", "nonce" },
"terms": { "serviceId", "deliverBy", "requestHash", "salt" } } }
Only the vault can submit a ReceiveWithAuthorization, so a signature can't be redirected. Your wallet never pays gas.
Order id and request hash
requestHash = keccak256(utf8(METHOD + " " + resource + "\n" + keccak256(body)))
resource = the path after /x/{id}, with its query string ("/" if empty)
orderId = keccak256(abi.encode(vault, chainId, buyer, serviceId,
amount, deliverBy, requestHash, salt))
The order id binds the payment to one request. Change the query or the body and the server refuses it; send it twice and the vault refuses it.
Checks
Each service promises these in the contract. The response must meet all of them.
| Check | Passes when | Refund reason |
|---|---|---|
| Status | HTTP 2xx | 1 · error status |
| On time | answered within maxLatencyMs | 2 · too slow |
| Format | JSON parses / text / image content type | 3 · wrong format |
| Keys | every requireKeys entry is present and not null | 4 · missing keys |
| Reachable | the seller answered at all | 5 · no answer |
| Expiry | a verdict was posted before deadline + 1 hour | 6 · expired (anyone can trigger) |
Every verdict stores keccak256(responseBody) on-chain, so a buyer can prove what was delivered.
Money
- Released: seller gets the price minus the fee (1%, up to half off for staking sellers). The fee goes to $CAVEAT stakers.
- Refunded after a failed check: buyer gets the price plus cover, 10% of the price, from the seller's bond.
- Refunded by the seller, or after expiry: buyer gets the price back. No penalty, no fee.
- Sellers need a 25 USDG bond to take orders. Open orders lock their cover. Withdrawals unlock after three days.
SDKs
JavaScript (Node 20+):
import { Buyer } from 'caveat-x402'; const buyer = new Buyer({ signer: wallet, maxPrice: 50_000n }); // 0.05 USDG cap const res = await buyer.fetch('{API}/x/1/'); res.status; await res.json(); res.receipt.verdict; // "released" or "refunded"
Python:
from eth_account import Account from caveat import Buyer r = Buyer(Account.from_key(KEY), max_price=50_000).fetch("{API}/x/1/") r.status, r.json(), r.receipt["verdict"]
Or with curl, after building the header yourself:
curl -i {API}/x/1/ # 402 with the terms
curl -i -H "X-PAYMENT: $PAYMENT" {API}/x/1/
Sellers
Register on the Sell page or with new Seller(signer, VAULT, USDG).register({…}). Forwarded requests carry X-Caveat-Order, X-Caveat-Buyer, X-Caveat-Request and X-Caveat-Signature: the assessor's signature over "Caveat order\n" + orderId + "\n" + requestHash. verifyCaveatRequest (JS) and verify_caveat_request (Python) check it. A seller can refund any open order with refund(orderId, 0, 0x0); no penalty.
Discovery
Contracts
Source and tests ship with the release. The vault has no upgrade path and no way for anyone, including the owner, to move held payments or bonds other than by the rules above. The owner can change the fee (max 5%) and where it goes, the cover (new orders only), the minimum bond, the expiry grace and withdrawal delay (within fixed bounds), and who may post verdicts.