Documentation
How Raygate brings x402 payments to the Beam blockchain.
What is Raygate?
Raygate is the first x402 payment facilitator built for Beam. It turns any HTTP API into a pay-per-request endpoint settled on-chain — without accounts, API keys, or subscriptions.
The x402 protocol extends HTTP with a native payment layer. When a client hits a gated endpoint, the server responds with 402 Payment Required. The client signs a payment authorization, retries the request, and the facilitator settles the payment on Beam. The entire round-trip takes about 3 seconds.
Why Beam Needs This
Base, Solana, Stellar, XRPL, and Polygon all have x402 facilitators. Beam does not — despite being purpose-built for gaming, AI, and compute, the exact verticals driving x402 adoption everywhere else.
Pay-per-asset lookup, pay-per-level unlock
Pay-per-inference, agent-to-agent commerce
Pay-per-query market data, trading signals
Pay-per-compute-unit, GPU rental
Without an x402 facilitator, Beam's APIs and AI inference endpoints are invisible to AI agents making autonomous payments across the x402 ecosystem. Raygate bridges that gap.
Deploying Permit2 on Beam
A critical prerequisite for Raygate was deploying Permit2 on Beam. Although Permit2 is deployed at a canonical address on most EVM chains, Beam (as an Avalanche subnet) did not have it.
We deployed Permit2 at its canonical address on Beam testnet using the deterministic CREATE2 factory that was already present on Beam. The deployment replayed the exact same calldata used on Ethereum and Avalanche C-Chain, producing the contract at the same deterministic address:
0x000000000022D473030F116dDEE9F6B43aC78BA3
View on explorer: Permit2 on Beam Testnet
This means any tooling, SDK, or agent that interacts with Permit2 on other chains works identically on Beam — no address changes, no compatibility shims. Mainnet deployment will follow before production launch.
Payment Flow
The x402 payment flow has six steps. The payer never submits a transaction — they sign an off-chain message, and the facilitator pays gas.
- 1Client requests resource
GET /api/market-data with no payment header.
- 2Server returns 402
Response includes price, token address, merchant wallet, and facilitator URL.
- 3Client signs Permit2 payload
EIP-712 typed data with token, amount, nonce, and 30-second deadline. No gas, no transaction.
- 4Client retries with signature
Same request + PAYMENT-SIGNATURE header containing the base64-encoded signed payload.
- 5Facilitator verifies locally
Pure signature check — zero RPC calls, under 50ms. Validates deadline, network, token, amount, and signer.
- 6Facilitator settles on Beam
Calls Permit2.permitTransferFrom — atomically verifies sig, transfers tokens, marks nonce used. ~3 seconds.
Why Permit2
The standard x402 EVM scheme uses transferWithAuthorization (EIP-3009), which USDC on Base natively supports. But Beam uses LayerZero-bridged USDC — an OFT wrapper that doesn't implement EIP-3009.
Permit2 (Uniswap's universal token allowance contract) solves this:
- •Works with any ERC-20 — USDC, WBEAM (WMC), USDT, or future Beam ecosystem tokens
- •Deployed at the canonical address 0x000000000022D473030F116dDEE9F6B43aC78BA3 on Beam testnet via deterministic CREATE2
- •Nonce bitmap provides on-chain replay protection — each signature is single-use
- •One-time approve(Permit2, maxUint256) per token, then every payment is a pure off-chain signature
- •Facilitator pays gas — payers never submit transactions
Token Approval (One-Time Setup)
Before Permit2 can transfer tokens on a payer's behalf, the payer must approve Permit2 to spend each token. This is a one-time on-chain transaction per token per wallet — after that, every payment is a gasless off-chain signature.
import { approvePermit2 } from "@raygate/client";
// One-time: approve Permit2 to spend USDC
await approvePermit2(walletClient, publicClient, USDC_ADDRESS);
// One-time: approve Permit2 to spend WBEAM (WMC)
await approvePermit2(walletClient, publicClient, WBEAM_ADDRESS);In the Playground, the "Approve Permit2" button handles this automatically. It checks the current allowance on load — if already approved, it stays disabled with a green checkmark. Each token (USDC, WBEAM) requires its own approval.
Supported Tokens on Beam Testnet
Raygate supports any ERC-20 token on Beam via Permit2. The demo uses two tokens from the Beam testnet:
| Token | Symbol | Decimals | Address |
|---|---|---|---|
| USD Coin | USDC | 6 | 0x007Fdc86...87397E3 |
| Wrapped BEAM | WBEAM (WMC) | 18 | 0xF65B6f9c...d248bFeA |
Note: BEAM is the native gas token on the Beam chain (like ETH on Ethereum). WBEAM is the ERC-20 wrapped version (on-chain symbol: WMC — Wrapped Merit Circle, from Beam's original name). Permit2 requires ERC-20 tokens, so payments in BEAM use the WBEAM wrapper. The facilitator pays gas in native BEAM.
Packages
@raygate/coreShared types, Permit2 ABI, Beam chain definitions, encode/decode utilities
@raygate/facilitatorStandalone Express service — /verify, /settle, /capabilities, /health
@raygate/expressOne-line Express middleware for gating any route with x402 payments
@raygate/clientClient library — beamFetch() handles the full 402 → sign → retry loop, plus approvePermit2() for one-time token approval
Quick Start
Gate an API endpoint:
pnpm add @raygate/express
import { paymentMiddleware } from "@raygate/express";
app.use(paymentMiddleware({
"GET /api/data": {
description: "Market data",
accepts: [{
scheme: "exact",
network: "eip155:4337",
maxAmountRequired: "100000", // 0.10 USDC
asset: "0x76BF5E7d2Bcb06b1444C0a2742780051D8D0E304", // USDC on Beam mainnet
payTo: "0xMERCHANT_WALLET",
facilitatorUrl: "https://facilitator.raygate.dev",
description: "Market data feed",
}],
},
}, { facilitatorUrl: "https://facilitator.raygate.dev" }));Make a payment-aware request from an AI agent:
import { createBeamFetch, approvePermit2 } from "@raygate/client";
// One-time setup: approve Permit2 for USDC
await approvePermit2(walletClient, publicClient, USDC_ADDRESS);
// Create a payment-aware fetch
const beamFetch = await createBeamFetch({
walletClient,
facilitatorUrl: "https://facilitator.raygate.dev",
});
// Use it like normal fetch — payments handled transparently
const res = await beamFetch("https://api.example.com/data");
const data = await res.json();What's Next: User as Transaction Origin
Today, the facilitator wallet appears as from on every settlement transaction — this matches the standard x402 design used by Coinbase on Base and other chains. The facilitator submits the Permit2 call, so it's the facilitator's address in the transaction log.
But Beam already has ERC-4337 Account Abstraction infrastructure deployed — an EntryPoint contract and a Paymaster — which opens a path to something better.
In the production Go implementation, we plan to integrate ERC-4337 so that the user appears as from on each settlement while the facilitator's Paymaster sponsors the gas. This means:
- •On-chain history shows which users called which APIs — a richer, more transparent activity graph
- •The facilitator still covers gas, preserving the gasless experience for payers
- •Every user who calls a gated endpoint becomes visible on-chain as the transaction origin
- •Beam gets a genuinely unique x402 implementation that no other chain's facilitator has
This is documented in the Raygate Whitepaper as a Phase 2 milestone.
About This Demo
This demo runs the full x402 payment flow on Beam testnet (chainId 13337). When you click "Execute" in the Playground:
- The payer's wallet must have approved Permit2 for the selected token (one-time, via the Approve button)
- A Permit2 EIP-712 payload is signed server-side using the demo payer's private key
- The signature is verified locally (zero RPC calls, under 50ms)
- The API endpoint is called and returns data
Permit2.permitTransferFromis submitted to Beam testnet — tokens transfer from payer to merchant atomically- The transaction confirms in ~2-3 seconds and balances update in the UI
All transactions are real on-chain settlements on Beam testnet. You can verify every transaction on the Beam Testnet Explorer.