PayGate is a high-performance, cross-chain payment layer designed to bridge the gap between traditional API services and the emerging economy of AI Agents. By implementing the HTTP 402 (Payment Required) standard, PayGate allows developers to monetize any infrastructure with instant, on-chain settlements.
Most traditional payment systems (Stripe, PayPal) are built for humans—they require UIs, credit cards, and recurring subscriptions. PayGate is built for Machine-to-Machine (M2M) commerce.
- The Problem: AI Agents often fail when they hit credit card paywalls or complex subscription requirements.
- The Solution: PayGate provides a protocol-level payment response (x402). If an agent calls a protected API, they receive a machine-readable 402 status. The agent then sends a fractional USDC payment on Base and retries the call with an
X-Paymentproof-of-payment header to immediately unlock the resource.
Users can register a unique, human-readable PayGate ID (e.g., alice.paygate.eth) via our custom ENS subdomain registrar on Ethereum Sepolia. This ID acts as your global merchant identity across the ecosystem.
Settlements occur on the Base Network (L2) using native USDC. This ensures:
- Near-Zero Fees: Micro-payments (e.g., $0.001) are economically viable.
- Sub-2 Second Finality: APIs unlock almost instantly after payment.
- Stable Pricing: Developers earn in USDC, avoiding crypto volatility.
Integrate monetization with one line of code. Our Next.js-compatible middleware handles:
- Cryptographic transaction verification.
- Real-time price validation.
- Automatic 402 status generation.
A premium, real-time analytics dashboard to track:
- Total revenue and API call volume.
- Active "PayGate ID" status.
- Recent transaction history and settlement logs.
A programmatic marketplace (/api/marketplace) where AI Agents can autonomously discover API providers based on category, price, and reliability.
PayGate leverages a hybrid cross-chain architecture to provide the best user experience and lowest costs.
graph TD
A[User/Merchant] -->|Registers| B(ENS Subdomain - Ethereum Sepolia)
B -->|Verified Identity| C(PayGate Dashboard)
D[AI Agent] -->|Calls API| E(x402 Middleware)
E -->|Returns 402| D
D -->|Pays USDC| F(Base Network L2)
F -->|Proof of Payment| E
E -->|Unlocks Data| D
- Framework: Next.js 15 (Turbopack)
- Styling: Tailwind CSS 4 & Framer Motion
- Blockchain Interface: Viem & Wagmi 2.0
- Onchain Components: Coinbase OnchainKit
- Streaming: Superfluid (for high-frequency streams)
- Backend/DB: Supabase
- Identity: ENS (Ethereum Name Service)
- Node.js 20+
- A wallet with Sepolia ETH (for ENS registration) and Base Sepolia USDC (for payments).
git clone https://github.com/dhruvxop19/paygate.git
cd paygate/paygate
npm installCreate a .env.local file in the root directory:
# Network Config
NEXT_PUBLIC_BASE_SEPOLIA_RPC=...
NEXT_PUBLIC_CHAIN_ID=84532
NEXT_PUBLIC_USDC_ADDRESS=...
# Identity (ENS)
PAYGATE_SUBDOMAIN_CONTRACT=0xf7f47FE64c7cbc99deDD53F31e1E9E189e1ee3BE
ETHEREUM_SEPOLIA_RPC=...
ADMIN_PRIVATE_KEY=...
# Backend
SUPABASE_URL=...
SUPABASE_ANON_KEY=...npm run devProtect any Next.js route handler by wrapping it with our paygateNext utility.
import { paygateNext } from 'paygate-x402'
export async function GET(request: Request) {
// 1. Validate payment against the Base network
const paymentCheck = await paygateNext(request, {
price: '0.005', // Cost in USDC
payTo: '0xYourMerchantWallet'
});
// 2. If unpaid, automatically returns Response with 402 status
if (paymentCheck) return paymentCheck;
// 3. Logic only executes if payment is cryptographically verified
return Response.json({
message: "Authorized access to premium AI resource.",
data: { ... }
});
}Every payment submitted via the X-Payment header is validated through three stages:
- Semantic Check: Validates the transaction format and chain ID.
- On-Chain Verification: Queries the Base network to ensure the transaction exists and is finalized.
- Attribute Matching: Confirms the amount, recipient, and token address (USDC) match the provider's requirements.
| Endpoint | Method | Description |
|---|---|---|
/api/register |
POST |
Register a new API provider service. |
/api/subdomain/check |
GET |
Verify availability of a PayGate ID label. |
/api/subdomain/register |
POST |
Claim an ENS subdomain (PayGate ID). |
/api/marketplace/discover |
GET |
Fetch available machine-payable endpoints. |
We welcome contributions from the community! Whether it's fixing bugs, improving documentation, or proposing new features for the x402 protocol, please open an issue or PR.
Built with ❤️ for the future of Autonomous Agent Commerce on Base.