Skip to main content
x402Escrow

x402Escrow on GitHub

This documentation section covers the implementation available on GitHub.
Clone, experiment, and adapt it to your use case.

Accept Payments for AI Inference

x402Escrow is a UUPS-upgradeable smart contract that locks USDC upfront using a signed off-chain authorization and then settles the actual cost when the job is complete. Unused funds return to the client automatically. It implements the x402 payment protocol that turns HTTP 402 “Payment Required” into a native on-chain settlement layer.

Who Is This For?

  • Service operators (facilitators) that run AI inference, MCP tool servers, or any metered API and want to get paid per request without invoices, subscriptions, or payment processors.
  • Agent builders (clients) that need autonomous software agents to pay for services programmatically, without human approval for every transaction.
  • Protocol integrators building on x402 who need a battle-tested escrow primitive with EIP-3009 support and timeout-based safety nets.

Core Use Cases

x402Escrow is built specifically for consumption-based AI billing.
  • AI services with usage-based, pay-per-token billing
  • Services where the actual costs are unknown at request time

How x402Escrow Works

1

Lock the maximum

The client signs an EIP-3009 authorization for the worst-case cost. No on-chain transaction required from the client.
2

Pay the actual

When the job completes, the facilitator calls release() with the real cost. The client gets the difference back.
3

Safety net

If the facilitator never settles, the client reclaims everything after the timeout. No admin intervention needed.

Zero protocol fees


Settlement in one transaction


Fully on-chain


The Problem It Solves

Traditional payment rails do not work for machine-to-machine commerce:
  • Credit cards require human interaction and charge 2.9% + $0.30 per transaction.
  • Subscriptions force flat pricing on variable-cost workloads.
  • Prepaid credits lock capital with no guarantee of refund.
  • Direct token transfers offer no dispute resolution or overpayment protection.
AI agents consuming services need a payment pattern that is autonomous, variable-cost, and trust-minimized. x402Escrow provides such a payment layer.

x402Escrow Key Features

EIP-3009 authorization

Clients sign off-chain; no approve+transfer dance, no MEV frontrunning.

Single-slot storage

Each escrow packs into 32 bytes. Gas-efficient by design.

Variable settlement

Facilitator pays only what the service actually costs; remainder returns automatically.

Permissionless refunds

Anyone can trigger a timeout refund. Enables gasless relayer patterns.

UUPS upgradeable

Contract logic can evolve; proxy state persists across upgrades.

Role-based access

Separate Owner, Admin, and Facilitator roles with least-privilege boundaries.

x402 Compatible

Maintains HTTP 402 semantics.Uses standard headers (PAYMENT-REQUIRED, PAYMENT-SIGNATURE).Only the settlement flow changes (escrow instead of direct payment).Fully backward-compatible for clients that support escrow parameters.

ERC-8183 Complementary

An agent can accept a job via ERC-8183 and then use x402Escrow to pay for the inference it needs to complete that job. The two protocols operate at different layers of the same agentic commerce stack.ERC-8183 answers:
“Did the agent complete the job?”
x402Escrow answers:
“How many tokens were consumed to complete the job?”

Deployed Contracts

NetworkAddressExplorer
Base0x9562f50f73d8ee22276f13a18d051456d8d137a0Basescan
Monad0x9562f50f73d8ee22276f13a18d051456d8d137a0Monad Explorer