# AgentPay x402 Facilitator

> **AgentPay** is the x402 payment infrastructure for autonomous AI agents. Verify EIP-712 grants and settle USDC payments across 5 EVM chains in a single HTTP call — no accounts, no API keys, no human approval required.

## Install

Paste this URL into your agent to install this skill:

```
https://x402-agent-pay.com/SKILL.md
```

## What This Skill Does

AgentPay lets your agent:
- **Verify** EIP-712 signed payment grants from other agents
- **Settle** USDC payments on Base, Ethereum, Optimism, Arbitrum, or Polygon
- **Register** itself as a payable endpoint (get a wallet address and API key)
- **Pay** other agents or APIs atomically via the x402 HTTP payment header
- **Create escrow** payments for 2-party transactions with human review

## Pricing

| Operation | Cost | Notes |
|-----------|------|-------|
| Verify grant | Free | Always 0% |
| Settle payment | 0.5% fee | Deducted from transfer |
| Register agent | Free | One-time |
| Escrow create | Free | Fee on settlement |
| Balance check | Free | — |

## Endpoints

### Verify a Payment Grant
```http
POST https://x402-agent-pay.com/x402/verify
Content-Type: application/json

{
  "grant": "<EIP-712 signed grant object>",
  "expectedAgent": "0x...",   // optional
  "amount": 1000000           // optional, in USDC base units
}
```
Returns: `{ valid: bool, error?: string, shouldCheckRevocation: bool }`

### Settle a Payment
```http
POST https://x402-agent-pay.com/x402/settle
Content-Type: application/json

{
  "grant": "<EIP-712 signed grant>",
  "amount": 1000000,          // USDC base units (6 decimals)
  "network": "base"           // base | ethereum | optimism | arbitrum | polygon
}
```
Returns: `{ success: bool, txHash: string, settled: number }`

### Register Your Agent
```http
POST https://x402-agent-pay.com/api/agentpay/register
Content-Type: application/json

{
  "name": "my-agent",
  "type": "ai_agent",         // ai_agent | business | device | personal
  "description": "What my agent does",
  "wallet": "0x..."           // optional, provide your own or get a custodial one
}
```
Returns: `{ api_key: string, wallet: string, endpoint_id: string }`

### Pay Another Agent
```http
POST https://x402-agent-pay.com/api/agentpay/pay
X-AgentPay-Key: <your-api-key>
Content-Type: application/json

{
  "to": "0x...",              // recipient wallet or endpoint_id
  "amount": 0.50,             // USDC amount
  "memo": "data query fee"
}
```
Returns: `{ tx_ref: string, settled: true, amount: 0.50 }`

### Create Escrow
```http
POST https://x402-agent-pay.com/api/agentpay/escrow/create
X-AgentPay-Key: <your-api-key>
Content-Type: application/json

{
  "to": "0x...",
  "amount": 5.00,
  "expires_hours": 24,
  "description": "Work order escrow"
}
```

## x402 HTTP Payment Header Usage

To pay any x402-protected API with AgentPay:

```typescript
import { createGrant, signGrant } from '@agentpay/x402';

const grant = await signGrant({
  principal: myWallet.address,
  agent: targetAgentAddress,
  totalBudget: 10_000_000n,    // $10 USDC
  perRequestCap: 500_000n,     // $0.50 per call
  expiration: BigInt(Date.now() / 1000 + 900)  // 15 min
}, myWallet);

const response = await fetch('https://api.example.com/paid-endpoint', {
  method: 'POST',
  headers: {
    'X-402-Payment': JSON.stringify(grant),
    'X-402-Facilitator': 'https://x402-agent-pay.com'
  }
});
```

## Supported Networks

| Network | Chain ID | USDC Contract |
|---------|----------|---------------|
| Base (recommended) | eip155:8453 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Ethereum | eip155:1 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
| Optimism | eip155:10 | 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85 |
| Arbitrum | eip155:42161 | 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 |
| Polygon | eip155:137 | 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 |

## Health Check

```http
GET https://x402-agent-pay.com/x402/health
```
Returns: `{ status: "ok", version: "2.0", chains: [...], uptime: "99.5%" }`

## Conformance

All 6 x402 conformance test vectors pass:

```http
GET https://x402-agent-pay.com/x402/conformance
```

## Resources

- Docs: https://x402-agent-pay.com/docs.html
- Quickstart: https://x402-agent-pay.com/getting-started.html
- GitHub (x402 spec): https://github.com/shawnhvac/x402
- Agent registration: https://x402-agent-pay.com/agent-signup
- OpenAPI spec: https://x402-agent-pay.com/.well-known/openapi.yaml
- Discovery: https://x402-agent-pay.com/.well-known/x402.json

## Contact

support@x402-agent-pay.com
