# X402 Protocol

AESC integrates the X402 payment protocol, which implements on-chain micropayments based on the HTTP 402 status code. It is particularly suited for the AI Agent economy and API monetization.

## Architecture

```
Client (User/AI Agent)
    |
    |-- 1. HTTP Request ----------------> Protected API Service
    |                                          |
    |                                    2. Returns 402 + Payment Requirements
    |                                          |
    |-- 3. EIP-712 Signed Payment ----> x402-relayer (Go Service)
    |                                          |
    |                                    4. Verify Signature + On-chain Settlement
    |                                          |
    <-- 5. API Response -----------------------+
```

## Core Components

| Component               | Description                                                                            |
| ----------------------- | -------------------------------------------------------------------------------------- |
| **x402-relayer**        | A standalone Go service responsible for signature verification and on-chain settlement |
| **Facilitator**         | Local verification/settlement module (EIP-712 signature verification)                  |
| **HTTP 402 Middleware** | Intercepts requests and returns payment requirements                                   |

## Supported Payment Tokens

<table><thead><tr><th width="98.41015625">Token</th><th width="267.9375">Contract Address (Testnet)</th><th>Contract Address (Mainnet)</th></tr></thead><tbody><tr><td>USDT</td><td>0x2F3a429D90e4aD9A4984EA98Ed05D3f6D69dFf37</td><td>TBD</td></tr><tr><td>USDC</td><td>TBD</td><td>TBD</td></tr></tbody></table>

## Detailed Payment Flow

1. **Client Request**: The client sends an HTTP request to an X402-protected API
2. **402 Response**: The server returns an HTTP 402 status code with a payment descriptor (PaymentRequired header), containing:
   * Payment amount
   * Token type (USDT/USDC)
   * Recipient address
   * Expiration time
3. **Offline Signing**: The client uses EIP-712 typed data signing to authorize the payment (`transferWithAuthorization`, EIP-3009)
4. **Verification and Settlement**: The x402-relayer verifies the signature validity and executes the token transfer on-chain
5. **Response Return**: After successful settlement, the original API response is returned to the client

## Features

* **No Gas Token Required**: Users pay with USDT/USDC without needing to hold AEX
* **EIP-712 Offline Signing**: Users do not need to authorize online, reducing interaction friction
* **EIP-3009 Compatible**: Uses `transferWithAuthorization` for authorized transfers
* **Independent Deployment**: The x402-relayer runs as a standalone service, not embedded in chain nodes

***

> **Developer Note**: 1 AEX = 10^6 wei precision (6 decimal places).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aesc.gitbook.io/aesc/developers/x402.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
