x402x is an advanced facilitator service that extends the base x402 protocol with additional features for enterprise use cases. It provides enhanced payment processing, analytics, and customization options.
Prerequisites
- Node.js and npm installed
- A SKALE Chain endpoint
- Understanding of x402 protocol
Configuration
Environment Variables
Create a .env file with x402x configuration:
# x402x Facilitator URL
FACILITATOR_URL=https://facilitator.x402x.dev/
# Facilitator router address
RECEIVING_ADDRESS=0x1Ae0E196dC18355aF3a19985faf67354213F833D
# Payment token configuration
PAYMENT_TOKEN_ADDRESS=0x61a26022927096f444994dA1e53F0FD9487EAfcf
PAYMENT_TOKEN_NAME="Axios USD"
# SKALE network configuration
NETWORK_CHAIN_ID=324705682
# Server port
PORT=3000
Basic Integration
Server Setup
Client Setup
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { paymentMiddleware, x402ResourceServer } from "@x402/hono";
import { ExactEvmScheme } from "@x402/evm/exact/server";
import { HTTPFacilitatorClient } from "@x402/core/server";
import type { Network } from "@x402/core/types";
import "dotenv/config";
const app = new Hono();
async function main() {
const facilitatorUrl = process.env.FACILITATOR_URL!;
const apiKey = process.env.X402X_API_KEY!;
const receivingAddress = process.env.RECEIVING_ADDRESS as `0x${string}`;
const paymentTokenAddress = process.env.PAYMENT_TOKEN_ADDRESS as `0x${string}`;
const paymentTokenName = process.env.PAYMENT_TOKEN_NAME || "Axios USD";
const networkChainId = process.env.NETWORK_CHAIN_ID || "324705682";
const network: Network = `eip155:${networkChainId}`;
// Initialize x402x facilitator client with authentication
const facilitatorClient = new HTTPFacilitatorClient({
url: facilitatorUrl,
headers: {
"X-API-Key": apiKey,
"Authorization": `Bearer ${apiKey}`,
},
});
const resourceServer = new x402ResourceServer(facilitatorClient);
resourceServer.register("eip155:*", new ExactEvmScheme());
// Apply payment middleware
app.use(
paymentMiddleware(
{
"GET /api/premium": {
accepts: [
{
scheme: "exact",
network: network,
payTo: receivingAddress,
price: {
amount: "50000", // 0.05 tokens
asset: paymentTokenAddress,
extra: {
name: paymentTokenName,
version: "1",
},
},
},
],
description: "Premium content with x402x",
mimeType: "application/json",
},
},
resourceServer
)
);
// Protected endpoint
app.get("/api/premium", (c) => {
return c.json({
message: "Premium content unlocked via x402x!",
features: ["analytics", "webhooks", "rate-limiting"],
timestamp: new Date().toISOString(),
});
});
const port = Number(process.env.PORT) || 3000;
serve({ fetch: app.fetch, port }, () => {
console.log(`Server running on http://localhost:${port}`);
console.log(`Using x402x facilitator: ${facilitatorUrl}`);
});
}
main().catch(console.error);
import { wrapFetchWithPayment } from "x402-fetch";
import { x402Client } from "@x402/core/client";
import { registerX402xScheme } from "@x402x/extensions";
import "dotenv/config";
async function main() {
const account = privateKeyToAccount(
process.env.PRIVATE_KEY as `0x${string}`
);
// 2. Create client and register x402x scheme
const client = new x402Client();
registerX402xScheme(client, "eip155:324705682", account);
// 3. Wrap fetch - it handles 402 automatically!
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
// 4. Use like normal fetch - payment happens transparently
const response = await fetchWithPayment("/api/premium-content", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ /* your data */ }),
});
const result = await response.json();
}
main();
Troubleshooting
Connection Issues
If you cannot connect to PayAI:
- Verify the facilitator URL is correct
- Check network connectivity
- Ensure API credentials are valid
- Review firewall settings
Payment Failures
Common causes and solutions:
| Issue | Solution |
|---|
| Invalid signature | Verify wallet configuration and signing |
| Insufficient balance | Ensure payer has enough tokens |
| Network mismatch | Check chain ID matches configuration |
| Expired authorization | Increase maxTimeoutSeconds |
Next Steps
Resources
x402x is a third-party enterprise service. Contact the x402x team for access, custom pricing, and enterprise support. The URLs in this guide are placeholders and will be updated when the service is publicly available.