← x402
402 → sign → retry loop transparently, so your code reads like a normal HTTP call.
Prerequisites
- An AgentCash wallet with a small USDC balance on Base (≥ $1 is plenty for testing — covers the access fees and a low-priced test purchase)
- A product URL from a supported merchant (Shopify storefronts, etc.)
- The AgentCash CLI or SDK — follow the AgentCash setup guide to install and initialize a wallet
~/.agentcash/wallet.json (EVM) and ~/.agentcash/solana-wallet.json (Solana). Top up the wallet with USDC on the network you plan to use before making any paid call.
End-to-end purchase
The example below uses@agentcash/fetch — the programmatic AgentCash SDK. Its executeFetch function handles the 402 → sign → retry loop transparently, so your code reads like a normal HTTP call.
What happens behind the scenes
executeFetchreceives a402 Payment Requiredfrom the proxy with aPAYMENT-REQUIREDheader. It signs an EIP-3009TransferWithAuthorization(off-chain only — the buyer never broadcasts) and retries the same request with aPAYMENT-SIGNATUREheader.- The proxy verifies the signature, broadcasts
transferWithAuthorizationon Base, and pays the gas. On the success response it returns anX-PAYMENT-RESPONSEheader carrying the on-chain transaction hash, whichexecuteFetchexposes aspaymentInfo.payment.transactionHash. - For step 1 the authorization is for 0.03 API fee — bundled into a single signed authorization.
GETcalls in steps 2 and 5 are free and use a normalfetch. TheX-Wallet-Addressheader scopes the read to the wallet that paid for the intent.- After step 4 returns, Rye places the order asynchronously. The intent moves to
placing_order, then tocompletedorfailed. See Checkout Intent Lifecycle for the full state machine.
Timing
Order placement runs asynchronously — your code does not block while Rye places the order at the merchant. Keep polling
GET /v1/checkout-intents?id=… until you see state: "completed" or state: "failed".
Failure modes
- Insufficient wallet balance — the on-chain transfer fails; the intent moves to
failedand no order is placed. - Offer retrieval fails (out of stock, unsupported product) —
state: "failed"after step 2; the $0.02 access fee is not refunded because the offer retrieval work was performed. - Order placement fails at the merchant —
state: "failed"after step 4; the purchase amount is automatically refunded to the signing wallet on-chain. - Signature expired between calls — the retry returns
400with a freshPAYMENT-REQUIRED;executeFetchre-signs and retries automatically.

