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
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 { 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);
import { wrapFetchWithPayment } from "x402-fetch";
import { x402Client } from "@x402/core/client";
import { registerX402xScheme } from "@x402x/extensions";
import { privateKeyToAccount } from "viem/accounts";
import "dotenv/config";
async function main() {
const account = privateKeyToAccount(
process.env.PRIVATE_KEY as `0x${string}`
);
const baseUrl = process.env.BASE_URL || "http://localhost:3001";
const networkChainId = process.env.NETWORK_CHAIN_ID || "324705682";
const client = new x402Client();
const networkId = `eip155:${networkChainId}` as `${string}:${string}`;
registerX402xScheme(client, "eip155:324705682", account);
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const fetchWithPayment = wrapFetchWithPayment(
fetch,
client
);
const premium_url = `${baseUrl}/api/premium`;
try{
const response = await fetchWithPayment(premium_url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);
}
catch(error){
console.error(
"[Client] Error:",
error instanceof Error ? error.message : error
);
process.exit(1);
}
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 x402x:
- 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
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.