Skip to main content
Batch settlement is the most cost-effective x402 scheme for repeated calls. You deposit USDC into an onchain escrow channel once, then each request signs an off-chain voucher. The server verifies vouchers instantly and claims them in batches.

How it works

  1. Deposit: Your wallet deposits USDC into a payment channel on-chain (the SDK handles this automatically when needed).
  2. Voucher: Each paid request includes a signed cumulative voucher for the channel’s total claimable amount.
  3. Verify: The server checks the voucher signature instantly — no on-chain transaction per request.
  4. Claim: The server periodically claims vouchers from many channels in a single on-chain batch transaction.

Set up the signer

The signer needs a publicClient with readContract capability so the SDK can recover channel state from on-chain. Without this, you’ll get invalid_batch_settlement_evm_cumulative_below_claimed errors.
The rpcUrl is critical — it gives the signer readContract access to query the channel’s on-chain state. Without it, the SDK cannot recover channel balances after a restart.

Deposit policy

By default, the SDK deposits 5× the per-request maximum when a channel needs funding. You can customize this:

Channel recovery

If your process restarts, the SDK recovers channel state from on-chain automatically on the next paid request. No local persistence is required — the on-chain state is the source of truth. For long-running clients, you can add file-based persistence to avoid the recovery round-trip:

Refund unused balance

When you’re done with a channel, refund the unused balance back to your wallet:

Common errors