Skip to main content
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:
# Your receiving address
RECEIVING_ADDRESS=0xyour_address_to_receive_payment

# SKALE network configuration
NETWORK_CHAIN_ID=324705682

Basic Integration

import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { paymentMiddleware, x402ResourceServer } from "@x402/hono";
import { ExactEvmScheme } from "@x402/evm/exact/server";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
import type { RouteConfig as X402RouteConfig } from "@x402/core/server";
import { HTTPFacilitatorClient } from "@x402/core/server";
import {
  registerRouterSettlement,
  registerSettlementHooks,
  createSettlementRouteConfig,
} from "@x402x/extensions";
import "dotenv/config";

const app = new Hono();
const PORT = 3000;

async function main() {

app.use(
  "/*",
  cors({
    origin: "*",
    credentials: false,
    exposeHeaders: ["PAYMENT-REQUIRED", "PAYMENT-RESPONSE"],
    allowHeaders: [
      "Content-Type",
      "PAYMENT-SIGNATURE",
      "PAYMENT-RESPONSE",
      "X-PAYMENT-SIGNATURE",
      "X-PAYMENT-RESPONSE",
    ],
  }),
);

  const facilitatorUrl = "https://facilitator.x402x.dev";
  const receivingAddress = process.env.RECEIVING_ADDRESS as `0x${string}`;
  const networkChainId = process.env.NETWORK_CHAIN_ID || "324705682";
  const network = `eip155:${networkChainId}`;

  // Initialize x402x facilitator client with authentication
  const facilitatorClient = new HTTPFacilitatorClient({
    url: facilitatorUrl
    });

  const resourceServer = new x402ResourceServer(facilitatorClient);
  registerExactEvmScheme(resourceServer, {
    networks: ["eip155:*"],
  });
  registerRouterSettlement(resourceServer);
  registerSettlementHooks(resourceServer);
  await resourceServer.initialize();

  const routes = {
    "GET /api/premium": createSettlementRouteConfig(
      {
        accepts: {
          scheme: "exact",
          network,
          payTo: receivingAddress,
          price: "$0.01",
        },
      },
      {
        // Dynamic fee: query facilitator /calculate-fee on 402 probe
        facilitatorUrl,
      },
  
    ) as X402RouteConfig,
  };
  app.use("/api/premium", paymentMiddleware(routes, resourceServer));

  app.get("/api/premium", async (c) => {
    console.log("[Server] Weather request received");
    return c.json({
      message: "Premium content unlocked via x402x!",
      features: ["analytics", "webhooks", "rate-limiting"],
      timestamp: new Date().toISOString(),
    });
  });

  serve({ fetch: app.fetch, port }, () => {
    console.log(`Server running on http://localhost:${port}`);
    console.log(`Using x402x facilitator: ${facilitatorUrl}`);
  });
}

main().catch(console.error);

Troubleshooting

Connection Issues

If you cannot connect to x402x:
  1. Verify the facilitator URL is correct
  2. Check network connectivity
  3. Ensure API credentials are valid
  4. Review firewall settings

Payment Failures

Common causes and solutions:
IssueSolution
Invalid signatureVerify wallet configuration and signing
Insufficient balanceEnsure payer has enough tokens
Network mismatchCheck chain ID matches configuration
Expired authorizationIncrease maxTimeoutSeconds

Next Steps

Resources


This entity — x402x — is deployed and activley supporting SKALE. These are 3rd party services that may have their own terms and conditions and privacy polices. Use these services at your own risk. AI and agents is a highly experimental space; the 3rd party software solutions may have bugs or be unaudited. You and your agents and your customers use all 3rd party services chosen at your own risk and per their terms.