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

# x402 Protocol

> Understanding the x402 payment protocol

The **x402 protocol** is an HTTP-based payment standard that enables seamless micropayments on the web. It extends the HTTP `402 Payment Required` status code to create a standardized payment negotiation flow.

## What is x402?

x402 solves the problem of web monetization by providing a standard way for clients and servers to negotiate and complete payments automatically, without manual intervention.

### Key Benefits

* **Automatic Payment Negotiation** - No manual payment flows
* **Multi-Chain Support** - Works with Base, Solana, and other chains
* **Standard HTTP Flow** - Uses familiar HTTP patterns
* **Proof of Payment** - Cryptographic verification of transactions
* **Developer Friendly** - Simple integration with existing tools

## How x402 Works

The x402 protocol follows a simple 4-step flow:

### 1. Initial Request

Your application makes a standard HTTP request to a payment-required endpoint:

```typescript theme={null}
POST /payments/x/pay
{
  "amount": 0.01,
  "currency": "USDC",
  "receiver": "username"
}
```

### 2. Payment Challenge (402 Response)

The server responds with `402 Payment Required` and includes payment details in the response headers:

```http theme={null}
HTTP/1.1 402 Payment Required
x-payment-request: <encoded-payment-requirements>
```

The payment request contains:

* Payment amount and currency
* Recipient address
* Blockchain network
* Transaction details

### 3. Payment Execution

Your x402 client automatically:

1. Decodes the payment requirements
2. Creates and signs a blockchain transaction
3. Submits the transaction to the network
4. Waits for confirmation

### 4. Retry with Proof

After payment confirmation, the client retries the original request with proof of payment:

```http theme={null}
POST /payments/x/pay
x-payment-response: <encoded-payment-proof>

{
  "amount": 0.01,
  "currency": "USDC",
  "receiver": "username"
}
```

The server verifies the payment and returns success:

```json theme={null}
{
  "code": 200,
  "msg": "0.01 USDC sent successfully",
  "data": {
    "txn_id": "...",
    "amount": 0.01,
    "receipt": "https://snack.money/x/username?txn=..."
  }
}
```

## Implementation Options

### Using x402 Clients

The easiest way to integrate x402 is using a pre-built client library:

**x402-axios** (Recommended for most applications)

```bash theme={null}
npm install x402-axios
```

**x402-fetch** (For minimal dependencies)

```bash theme={null}
npm install x402-fetch
```

See our [SDK Examples](/examples/overview) for implementation guides.

### Using the CLI

For command-line usage, use the Snack Money CLI:

```bash theme={null}
npx snackmoney send x/username 0.01
```

Learn more in the [CLI documentation](/cli/overview).

## Supported Networks

Snack Money's x402 implementation supports:

* **Base** (EVM) - USDC payments on Base mainnet
* **Solana** (SVM) - USDC payments on Solana mainnet

## Security

x402 provides strong security guarantees:

* **Cryptographic Proofs** - All payments are verified on-chain
* **No Custody** - You maintain control of your private keys
* **Transparent** - All transactions are publicly verifiable
* **Standard Protocol** - Open specification, no vendor lock-in

## Learn More

* [Getting Started Guide](/introduction/getting-started) - Send your first payment
* [SDK Examples](/examples/overview) - Integration examples
* [x402 Specification](https://github.com/coinbase/x402) - Full protocol documentation
