money-bills-simplex402 Payments

Treza integrates the x402 protocolarrow-up-right to enable instant, autonomous stablecoin micropayments for API access. AI agents and developers can pay for Treza services programmatically using USDC on Base — no API keys, subscriptions, or manual billing required.

What is x402?

x402 is an open payment protocol built by Coinbasearrow-up-right that uses the HTTP 402 Payment Required status code. When a client requests a paid resource:

  1. The server responds with 402 and payment instructions (price, network, recipient)

  2. The client signs a USDC payment

  3. The client retries the request with a Payment-Signature header

  4. The server verifies the payment, returns the data, and settles on-chain

Payments are instant, permissionless, and settled in USDC on Base (L2).

How Treza Uses x402

The following Treza API endpoints support x402 payments when enabled:

Endpoint
Method
Price
Description

/api/enclaves/{id}/attestation

GET

$0.001

Retrieve enclave attestation document with PCR measurements

/api/enclaves/{id}/attestation/verify

POST

$0.01

Full cryptographic verification with compliance checks

When x402 is disabled (default for development), these endpoints work normally without payment.

Payment Flow

Client                          Treza API                     Facilitator         Base L2
  │                                │                              │                  │
  │── GET /attestation ───────────▶│                              │                  │
  │                                │                              │                  │
  │◀── 402 Payment Required ───────│                              │                  │
  │    price: $0.001               │                              │                  │
  │    network: eip155:8453        │                              │                  │
  │    payTo: 0xTreza...           │                              │                  │
  │                                │                              │                  │
  │── Sign USDC payment ──┐        │                              │                  │
  │◀── Payment-Signature ─┘        │                              │                  │
  │                                │                              │                  │
  │── GET /attestation ───────────▶│                              │                  │
  │    + Payment-Signature         │                              │                  │
  │                                │── Verify payment ───────────▶│                  │
  │                                │◀── Valid ─────────────────── │                  │
  │                                │                              │                  │
  │◀── 200 Attestation Data ───────│                              │                  │
  │                                │── Settle payment ───────────▶│── USDC tx ──────▶│
  │                                │                              │                  │

Client-Side: Paying for Treza Services

Using the Treza SDK (Enclave as Wallet)

The most powerful pattern is using a Treza Enclave as the payment wallet itself. The private key lives inside the hardware-isolated TEE — it never leaves the enclave boundary.

Install Dependencies

Auto-Paying Fetch

The simplest approach — createEnclaveFetch returns a fetch function that automatically handles 402 responses:

x402 Client (Advanced)

For more control, use the x402 client directly:

Enclave Account (Low-Level)

Create a viem-compatible account backed by the enclave for use with any x402 library:

Using Any x402 Client (External Wallet)

You don't need the Treza SDK to pay. Any x402-compatible wallet works:

Using curl (Manual)

To inspect the 402 response without paying:

Server-Side: Adding x402 to Your Own Endpoints

If you're building on the Treza platform and want to monetize your own API endpoints, use the withX402Payment wrapper.

Basic Usage

With Bazaar Discovery

Make your endpoint discoverable by AI agents on the x402 Bazaararrow-up-right:

Environment Variables

Variable
Required
Default
Description

X402_ENABLED

No

false

Set to true to enable x402 payment gating

TREZA_X402_PAY_TO

Yes (if enabled)

Wallet address to receive USDC payments

X402_NETWORK

No

eip155:84532

Network identifier (Base Sepolia for testnet)

X402_FACILITATOR_URL

No

https://www.x402.org/facilitator

Payment verification facilitator

Testnet Configuration

Mainnet Configuration

Discovering Payable Services

AI agents can discover Treza's x402-payable endpoints through the Bazaar:

Security Model

Layer
Protection

TEE Signing

Payment signatures are created inside the hardware-isolated enclave — private keys never leave the Nitro Enclave boundary

Attestation Verification

Optional pre-signing attestation check ensures the enclave is untampered before authorizing payments

Facilitator Verification

Payment signatures are verified by the Coinbase facilitator before the server returns data

On-Chain Settlement

Payments settle as real USDC transfers on Base, providing an immutable audit trail

Replay Protection

Each payment signature is bound to a specific request and cannot be reused

Architecture

FAQ

Do I need USDC to use Treza? Only if x402 is enabled on the endpoint you're calling. During development and on testnet, x402 is disabled by default.

Which network are payments on? Base (Coinbase L2). Testnet uses Base Sepolia, mainnet uses Base mainnet. Both settle in USDC.

Can I use a regular wallet instead of an enclave? Yes. Any viem-compatible account or x402 client works. The enclave-as-wallet pattern is optional — it just adds the security of TEE-based key management.

How much do API calls cost? Attestation retrieval is $0.001 per call. Full verification is $0.01 per call. Prices are configurable per endpoint.

Is there a minimum balance? No minimum. You just need enough USDC in your wallet to cover the call price.

Last updated