x402 Payments
Dispatch uses x402 — Coinbase's open HTTP-native payment protocol — to settle USDC micropayments on every compute job. No custom token, no staking, no bridging. Workers get paid the moment a job completes.
How x402 works
x402 turns HTTP 402 ("Payment Required") from a vestigial status code into a real payment flow:
- Client sends a request to a paid endpoint
- Server returns
402 Payment Requiredwith payment details in the response - Client signs a stablecoin payment off-chain
- Client retries the request with the signed payment in the
X-PAYMENTheader - Server verifies the payment through a facilitator and processes the request
Client Server Facilitator
│ │ │
│ POST /v1/jobs/commit/fast │ │
│ ────────────────────────────▶│ │
│ │ │
│ 402 { accepts: [...] } │ │
│◀──────────────────────────── │ │
│ │ │
│ sign payment off-chain │ │
│ │ │
│ POST + X-PAYMENT header │ │
│ ────────────────────────────▶│ verify payment │
│ │ ───────────────────────────▶│
│ │◀─────────── ok ──────────── │
│ 201 { job_id } │ │
│◀──────────────────────────── │ │Chain-specific schemes
Dispatch runs two coordinators, each with its own x402 payment scheme:
Monad (EVM)
import { ExactEvmScheme } from "@x402/evm/exact/server";
const resourceServer = new x402ResourceServer(
new HTTPFacilitatorClient({ url: "https://x402-facilitator.molandak.org" })
).register("eip155:10143", new ExactEvmScheme());- Network:
eip155:10143(Monad testnet) - Asset: USDC on Monad (
0x534b2f3A21130d7a60830c2Df862319e593943A3) - Facilitator:
https://x402-facilitator.molandak.org - Scheme:
ExactEvmScheme— exact-amount EVM payment
Solana (SVM)
import { ExactSvmScheme } from "@x402/svm/exact/server";
const resourceServer = new x402ResourceServer(
new HTTPFacilitatorClient({ url: "https://www.x402.org/facilitator" })
).register("solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1", new ExactSvmScheme());- Network:
solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1(Solana devnet) - Facilitator:
https://www.x402.org/facilitator - Scheme:
ExactSvmScheme— exact-amount SPL payment
Payment middleware
The coordinator uses @x402/express middleware to gate the commit endpoints:
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
const middleware = paymentMiddleware(buildPaymentConfig(config), resourceServer);
app.use(middleware);The buildPaymentConfig() function creates x402 resource definitions for each endpoint:
{
"POST /v1/jobs/commit/fast": {
accepts: [{ scheme: "exact", price: "$0.010", network, payTo, asset }],
description: "Fast compute job",
mimeType: "application/json",
},
"POST /v1/jobs/commit/cheap": {
accepts: [{ scheme: "exact", price: "$0.001", network, payTo, asset }],
description: "Cheap compute job",
mimeType: "application/json",
},
}Testnet mode
Set TESTNET_MODE=true to disable x402 payment gating entirely. The commit endpoints accept requests directly without any payment. Useful for local development and testing.
TESTNET_MODE=true pnpm --filter coordinator-monad startSDK payment handling
The ComputeRouter SDK handles x402 payments automatically when configured with an x402 client:
const router = new ComputeRouter({
coordinatorUrls: {
monad: "http://localhost:4010",
solana: "http://localhost:4020",
},
x402Clients: {
monad: monadX402Client, // handles 402 → sign → retry
solana: solanaX402Client,
},
});The X402ClientLike interface:
interface X402ClientLike {
getPaymentRequiredResponse(
getHeader: (name: string) => string | null | undefined,
body?: unknown,
): unknown;
createPaymentPayload(paymentRequired: unknown): Promise<unknown>;
encodePaymentSignatureHeader(paymentPayload: unknown): Record<string, string>;
}When the SDK receives a 402 response, it:
- Extracts payment requirements from the response
- Creates a signed payment payload
- Encodes it as an
X-PAYMENTheader - Retries the request
If no x402Client is configured and the coordinator returns 402, the SDK throws an error. Either enable testnet mode or provide an x402 client.
x402 packages
Dispatch uses x402 v2.x packages:
| Package | Purpose |
|---|---|
@x402/express | paymentMiddleware and x402ResourceServer |
@x402/core/server | HTTPFacilitatorClient |
@x402/evm/exact/server | ExactEvmScheme for Monad |
@x402/svm/exact/server | ExactSvmScheme for Solana |
@x402/fetch | wrapFetchWithPayment (client-side) |