Skip to main content

The Killer Combo

x402 payments are USDC transfers. Session keys on CHIPI wallets authorize transfers without requiring the owner key each time. This makes x402 + sessions ideal for:
  • AI agent autonomous API consumption
  • Streaming data feeds (pay-per-query)
  • Backend automation (server-to-server payments)
  • Mobile apps with “subscribe for X hours” UX

React Implementation

How It Works Under the Hood

  1. Session creation: Generate a temporary keypair, encrypt private key with user’s PIN
  2. Session registration: Register the session public key on the wallet contract (one owner signature)
  3. Session constraint: allowedEntrypoints: ["transfer"] restricts the session to only USDC transfer calls
  4. x402 payment: When a 402 is received, the hook uses executeTransactionWithSession() instead of executeTransaction() — the session key signs automatically

Node.js Backend Automation

For server-side automation where you want to consume paid APIs:

On-Chain Spending Limits

Session keys alone don’t enforce dollar limits — maxCalls caps the number of transactions, not the amount. For real budget control, use Spending Policies:
The contract enforces this automatically — if a payment exceeds the per-call limit or the rolling window total, the transaction reverts on-chain. No middleware or backend enforcement needed.
Spending policies require CHIPI v33 wallets. See the full guide: Spending Policies.

Three Layers of Protection

For production x402 deployments, use all three.

Security Considerations

Session Scope

Always restrict session keys to the minimum required permissions:
This creates a comprehensive spending cap:
  • Per-request limit: maxPerCall enforced on-chain ($0.10 per API call)
  • Session window limit: maxPerWindow enforced on-chain ($10 per 6 hours)
  • Transaction count limit: maxCalls: 100 enforced on-chain
  • Client-side guard: maxPaymentAmount: "0.10" (early rejection, saves gas)

Session Expiry Fallback

If the session expires during a payment, the hook falls back to requiring the owner’s signature (wallet popup / biometrics / PIN):

Best Practices

  1. Set spending limits: Always configure maxPaymentAmount and session maxCalls
  2. Whitelist merchants: Use allowedRecipients when possible
  3. Monitor payments: Use onPaymentComplete callback for logging/analytics
  4. Short sessions: Prefer shorter session durations with renewal over long-lived sessions
  5. Transfer-only: Always set allowedEntrypoints: ["transfer"] for x402 sessions