x402
PROTOCOL

The "Payment Required" Protocol for the EVM. High-frequency, unidirectional state channels for the API economy.

PAYMENT REQUIRED ///HTTP 402 ///STATE CHANNELS ///MICRO-PAYMENTS ///OFF-CHAIN SIGS ///ON-CHAIN SETTLEMENT ///
PAYMENT REQUIRED ///HTTP 402 ///STATE CHANNELS ///MICRO-PAYMENTS ///OFF-CHAIN SIGS ///ON-CHAIN SETTLEMENT ///

The best way to accept digital payments.

Built around the HTTP 402 status code, x402 enables users to pay for resources via API without registration, emails, OAuth, or complex signatures.

No Fees

x402 as a protocol has 0 fees for either the customer or the merchant.

Instant Settlement

Accept payments at the speed of the blockchain. Money in your wallet in 2 seconds, not T+2.

Blockchain Agnostic

x402 is not tied to any specific blockchain or token, its a neutral standard open to integration by all.

Frictionless

As little as 1 line of middleware code. Customers and agents aren't required to create an account.

Security & Trust

Security via an open standard. Anyone can implement or extend x402. Not tied to any centralized provider.

Web Native

Activates the dormant 402 HTTP status code and works with any HTTP stack via headers.

INTERACTIVE DEMO
PROTOCOL HANDSHAKE

Client

Browser / Agent

ERR:402
200 OK

Server

Resource Provider

_waiting...

STREAMING_DEMO

Total Cost
$0.0000
Micro-TXs
0
Gas Fees: $0.00
All 0 transactions occurred off-chain via x402 signatures.
DEVELOPER EXPERIENCE

1 Line of Code

Just add a single line of code in your app, and you can require a USDC payment for each incoming request.

x402 allows any web developer to accept crypto payments without the complexity of having to interact with the blockchain. If a request arrives without payment, the server responds with HTTP 402.

VIEW SDK DOCS
import { paymentMiddleware } from 'x402';// 1. Configure your priceapp.use(paymentMiddleware("0xYourWalletAddress",{"/api/premium": "$0.01"}));// 2. Resulting HeaderHTTP/1.1 402 Payment RequiredX-Price: 0.01 USDC X-Contract: 0x8021...

Powering Next-Gen
Digital Commerce

AI AGENTS

Agents can use the x402 Protocol to pay for API requests in real-time. No human intervention, no credit cards, just autonomous code paying code.

CLOUD STORAGE

Customers can easily access storage services without account creation. Upload, pay per GB, and leave. true "Serverless" usage.

CONTENT CREATORS

x402 unlocks instant transactions, enabling true micropayments for content. Unlock a video for $0.02 without a monthly subscription.

x402 unlocks new monetization models

Offering developers and content creators a frictionless way to earn revenue from small transactions without forcing subscriptions or showing ads.

Why x402?

THE PROBLEM

Current payment systems create massive friction for API monetization and micro-transactions. This prevents viable business models:

  • Account Creation Friction: Users must create accounts, verify emails, and link payment methods before accessing any paid API.
  • Subscription Lock-In: Developers are forced into monthly subscriptions even for occasional API usage, leading to wasted spend.
  • High Payment Fees: Credit card processors charge 2-3% + $0.30 per transaction, making micro-payments economically impossible.
  • Slow Settlement: Traditional payment rails take 2-7 days to settle, creating cash flow problems for API providers.
  • Gas Fee Barrier: Even L2 blockchain transactions cost $0.01-0.10, too expensive for API calls priced at $0.0001.

THE SOLUTION

x402 eliminates payment friction through HTTP-native, cryptographically-secured state channels. The protocol enables:

  • Zero Account Friction: Users pay instantly with their wallet—no registration, no email verification, no OAuth flows.
  • True Pay-Per-Use: Pay exactly for what you consume. Request 10 API calls? Pay for 10. No monthly minimums or subscriptions.
  • Zero Protocol Fees: x402 charges no fees. 100% of payment goes to the API provider, unlike Stripe's 2.9% cut.
  • Instant Settlement: Funds arrive in provider's wallet in 2 seconds, not T+2 days. Immediate liquidity for businesses.
  • Gas-Free Micro-Payments: Thousands of API calls consolidated into a single on-chain transaction. Pay $0.0001 per call without gas fees.

MARKET OPPORTUNITY

$200B+

Global API economy market size, with x402 unlocking new monetization models for developers.

10,000x

More transactions possible compared to on-chain payments, enabling true micro-payment economies.

0%

Protocol fees. Unlike payment processors that take 2-3%, x402 is a neutral, open standard.

Protocol Architecture

LAYER 1 (Ethereum)
DepositContract
Locks user funds
SettlementLogic
Verifies final sig & distributes
OFF-CHAIN COMMUNICATON
CRYPTOGRAPHIC
SIGNATURES
LAYER 2 (The App)
Client (Browser)
Signs state updates
Provider (Server)
Verifies & Aggregates Sigs

Technical Specifications

Protocol Flow

The x402 protocol follows a simple, HTTP-native flow:

1. Initial Request

Client makes HTTP request to protected resource. Server checks for payment signature in headers.

2. 402 Response

If no valid payment, server returns HTTP 402 with payment details (price, contract address, nonce).

3. Payment Signature

Client signs state update with new balance. Signature proves authorization to deduct funds from channel.

4. Resource Delivery

Client retries request with signature. Server verifies signature and delivers resource.

State Channel Mechanics

// State channel structure struct Channel { address client; // Client wallet address address provider; // API provider address uint256 deposit; // Initial deposit amount uint256 balance; // Current balance uint256 nonce; // Prevents replay attacks uint256 timeout; // Withdrawal timeout period bool active; // Channel status } // Payment signature format (EIP-712) struct PaymentSignature { uint256 newBalance; // Updated balance after payment uint256 nonce; // Incremented nonce bytes signature; // Client's ECDSA signature }

Supported Networks

x402 works on any EVM-compatible blockchain:

Ethereum
Mainnet
Arbitrum
L2
Optimism
L2
Base
L2
Polygon
Sidechain

Security & Trust

Cryptographic Guarantees

x402 provides mathematical security through cryptographic primitives:

  • EIP-712 Signatures: Structured data signing prevents signature malleability and ensures clients can only authorize specific balance updates.
  • Nonce Protection: Incrementing nonces prevent replay attacks. Each signature is valid for exactly one transaction.
  • Balance Constraints: Smart contracts enforce that providers cannot withdraw more than the signed balance permits.

Dispute Resolution

Built-in mechanisms protect both clients and providers:

  • Timeout Withdrawals: If provider goes offline, clients can withdraw remaining balance after timeout period (typically 7 days).
  • Challenge Period: Providers submit final signature on-chain. Clients have 24 hours to challenge with a higher nonce signature.
  • Fraud Proofs: If provider submits old signature to steal funds, client can prove fraud with newer signature and claim full deposit.

Attack Resistance

x402 is designed to resist common attack vectors:

Replay Attacks

Nonces and channel IDs ensure each signature is valid for exactly one specific payment in one specific channel.

Double Spending

Smart contract enforces that total withdrawals cannot exceed deposited amount, preventing double-spend attempts.

Griefing

Timeout mechanisms ensure neither party can lock funds indefinitely. Clients always have exit option.

Frequently Asked Questions

Even L2s cost $0.01-$0.10. For AI inference or API calls costing $0.0001, L2 is too expensive. x402 consolidates thousands of calls into ONE on-chain transaction.

Yes. The user locks funds. The provider cannot take more than signed. The user can withdraw funds after a timeout if the provider disappears.

x402 supports any ERC-20 token. Most common are USDC, USDT, and DAI for stable pricing. ETH and WETH are also supported for native payments.

No protocol limits. Channel capacity is determined by initial deposit. You can make unlimited micro-payments until deposit is exhausted.

Unused funds remain in the channel. Close the channel anytime to withdraw remaining balance back to your wallet. Refunds are instant and gas-free.

Currently x402 supports unidirectional channels (client → provider). Multi-party channels are planned for v2 to enable agent-to-agent payments.

x402 is a neutral protocol. Compliance depends on implementation. Providers can add KYC/AML checks before opening channels if required by jurisdiction.

Signature verification adds ~50ms latency. Negligible for most APIs. Providers can batch verify signatures for high-throughput scenarios.

Add one line of middleware to your Express/FastAPI/Flask app. SDKs available for JavaScript, Python, Go, and Rust. Full docs at x402.dev.

Off-chain payments continue normally. Only channel open/close operations require on-chain transactions, so congestion doesn't affect API usage.