> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fortytwo.network/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Programmable escrow for metered AI and agent services on Base and Monad.

<Badge color="gray">x402Escrow</Badge>

<Card title="x402Escrow on GitHub" icon="github" href="https://github.com/Fortytwo-Network/fortytwo-x402Escrow" cta="github.com/Fortytwo-Network/fortytwo-x402Escrow" vertical>
  This documentation section covers the implementation available on GitHub.<br />Clone, experiment, and adapt it to your use case.
</Card>

## 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 <Icon icon="arrow-up-right" />](https://www.x402.org/) 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

<Steps>
  <Step title="Lock the maximum">
    The client signs an EIP-3009 authorization for the worst-case cost. No on-chain transaction required from the client.
  </Step>

  <Step title="Pay the actual">
    When the job completes, the facilitator calls `release()` with the real cost. The client gets the difference back.
  </Step>

  <Step title="Safety net">
    If the facilitator never settles, the client reclaims everything after the timeout. No admin intervention needed.
  </Step>
</Steps>

<Columns cols={3}>
  <Card title="Zero protocol fees">
    <br />
  </Card>

  <Card title="Settlement in one transaction">
    <br />
  </Card>

  <Card title="Fully on-chain">
    <br />
  </Card>
</Columns>

## 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

<Columns cols={3}>
  <Card title="EIP-3009 authorization">
    Clients sign off-chain; no approve+transfer dance, no MEV frontrunning.
  </Card>

  <Card title="Single-slot storage">
    Each escrow packs into 32 bytes. Gas-efficient by design.
  </Card>

  <Card title="Variable settlement">
    Facilitator pays only what the service actually costs; remainder returns automatically.
  </Card>

  <Card title="Permissionless refunds">
    Anyone can trigger a timeout refund. Enables gasless relayer patterns.
  </Card>

  <Card title="UUPS upgradeable">
    Contract logic can evolve; proxy state persists across upgrades.
  </Card>

  <Card title="Role-based access">
    Separate Owner, Admin, and Facilitator roles with least-privilege boundaries.
  </Card>
</Columns>

<Columns cols={2}>
  <Card title="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.
  </Card>

  <Card title="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:<br />
    *"Did the agent complete the job?"*

    x402Escrow answers:<br />
    *"How many tokens were consumed to complete the job?"*
  </Card>
</Columns>

## Deployed Contracts

| Network   | Address                                      | Explorer                                                                                                                  |
| --------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **Base**  | `0x9562f50f73d8ee22276f13a18d051456d8d137a0` | [Basescan <Icon icon="arrow-up-right" />](https://basescan.org/address/0x9562f50f73d8ee22276f13a18d051456d8d137a0)        |
| **Monad** | `0x9562f50f73d8ee22276f13a18d051456d8d137a0` | [Monad Explorer <Icon icon="arrow-up-right" />](https://monadscan.com/address/0x9562f50f73d8ee22276f13a18d051456d8d137a0) |
