xGate
xGate lets developers monetize APIs & WebSockets with on-chain, pay-per-use crypto payments.
Problem Statement
xGate is a developer-first platform that lets anyone monetize their backend APIs and WebSockets with crypto — instantly, without deploying new smart contracts or integrating complex payment SDKs.The core insight behind xGate is that x402, a new payment standard for decentralized access control, can serve as a universal billing layer for any networked service — from REST APIs to live WebSocket feeds. This means developers can charge per request, per minute, or per session using stablecoins like USDC on Base, all with a few lines of setup.Here’s how it works: When a developer registers a backend with xGate, we generate a secure proxy endpoint for their API or WebSocket. This proxy automatically enforces crypto-based payments using the x402 protocol. Whenever a user connects or makes a request, xGate verifies a signed payment authorization from their wallet, settles it via the x402 facilitator, and seamlessly forwards the traffic to the original backend.If the connection expires — for example, after one minute on a WebSocket — xGate automatically sends a renewal signal (402 Payment Required), prompting the client to reauthorize payment and extend the session. All of this happens invisibly: the developer doesn’t need to write payment logic, and the user doesn’t have to manually refresh, switch tabs, or reauthenticate.From the user’s perspective, it feels like a normal API or socket connection — but under the hood, every packet is backed by verified on-chain payment. For developers, xGate provides transparent revenue tracking and a fully trustless settlement pipeline. And because it’s built on Base and the x402 standard, it’s interoperable with any L2 wallet or app that supports ERC-20 assets.The brilliance of xGate lies in how it abstracts away all the visible edges of Web3 payment complexity. No more API keys, no fiat rails, no credit card dependencies — just decentralized pay-per-use infrastructure that feels as smooth as the Web2 internet.In short, xGate transforms APIs into crypto-native revenue streams. Developers can deploy their services, set a price, and start earning — all without touching a line of smart contract code. We believe this is how the next generation of decentralized applications will fund themselves: monetization embedded at the protocol layer, not the platform layer.
Solution
xGate is built using TypeScript, React, Node.js, and Express, with MongoDB (via Mongoose) handling storage for API and WebSocket configurations. The entire system is designed around the x402 protocol, a new decentralized standard for metered access payments.The core integration revolves around x402’s facilitator API, which manages both verification and settlement of payments in stablecoins like USDC on Base Sepolia. On the frontend, xGate uses wagmi and RainbowKit to handle wallet connections and payment signing. Once a user initiates a connection or request, exact.evm.createPayment() generates a signed payment payload, which is then sent to the backend through either HTTP headers or WebSocket query parameters.On the backend, the Express server validates payments using x402’s verify() function, ensuring that the payment matches the expected price and asset on-chain. Once verified, xGate calls settle() through the facilitator, triggering automatic on-chain transfers from the user’s wallet to the developer’s payout address. The backend maintains a real-time proxy layer using the ws library, which pipes user messages to the developer’s actual WebSocket or API after successful payment authorization.The most technically sophisticated part of xGate is its auto-renewal payment flow for WebSockets. Every connection has a predefined lifespan (for example, one minute). When the session is about to expire, the backend sends a structured 402 Payment Required signal over the same connection, prompting the client to automatically generate and submit a new payment. This approach eliminates any user interruption and keeps continuous streaming services — like data feeds or multiplayer backends — monetized minute by minute.During development, one of the biggest technical hurdles was that browsers do not support sending custom headers in WebSocket handshakes. To overcome this, xGate embeds the encoded payment directly into the connection URL (?payment=<encoded>), which the backend then decodes and verifies. This small but critical workaround made the system browser-compatible without compromising on-chain security or cryptographic integrity.Another key decision was to use Base for fast settlement and low gas fees. Its developer-friendly tooling allowed us to simulate the full lifecycle of microtransactions with almost no latency, which was critical for per-minute WebSocket billing.By combining x402’s open facilitator architecture with a lightweight proxy infrastructure, xGate delivers a fully trustless pay-per-use experience for APIs and WebSockets — no custodial intermediaries, no centralized accounts, and no manual billing cycles. Developers can monetize their backend instantly, while users enjoy seamless, on-chain authenticated access in real time.
Hackathon
ETHOnline 2025
2025
Contributors
- krish858
18 contributions