Skip to main content
PayAI is a hosted facilitator service that simplifies x402 payment processing. Instead of running your own facilitator infrastructure, you can use PayAI’s endpoints to handle payment verification and settlement.

Prerequisites

  • Node.js and npm installed
  • A SKALE Chain endpoint
  • Basic understanding of x402 protocol

Configuration

Environment Variables

Create a .env file with PayAI configuration:
# PayAI Facilitator URL
FACILITATOR_URL=https://facilitator.payai.example.com

# Facilitator Router Address
RECEIVING_ADDRESS=0xFacilitatorRouterAddress

# Payment token configuration
PAYMENT_TOKEN_ADDRESS=0x61a26022927096f444994dA1e53F0FD9487EAfcf
PAYMENT_TOKEN_NAME="Axios USD"

# SKALE network configuration
NETWORK_CHAIN_ID=324705682

# Server port
PORT=3000

Integration with PayAI

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() {
  // Point to PayAI facilitator
  const facilitatorUrl = process.env.FACILITATOR_URL!;
  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 PayAI facilitator client
  const facilitatorClient = new HTTPFacilitatorClient({ 
    url: facilitatorUrl 
  });
  
  const resourceServer = new x402ResourceServer(facilitatorClient);
  resourceServer.register("eip155:*", new ExactEvmScheme());

  // Apply payment middleware
  app.use(
    paymentMiddleware(
      {
        "GET /api/data": {
          accepts: [
            {
              scheme: "exact",
              network: network,
              payTo: receivingAddress,
              price: {
                amount: "10000", // 0.01 tokens
                asset: paymentTokenAddress,
                extra: {
                  name: paymentTokenName,
                  version: "1",
                },
              },
            },
          ],
          description: "Premium data access",
          mimeType: "application/json",
        },
      },
      resourceServer
    )
  );

  // Protected endpoint
  app.get("/api/data", (c) => {
    return c.json({
      message: "Premium data unlocked via PayAI!",
      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 PayAI facilitator: ${facilitatorUrl}`);
  });
}

main().catch(console.error);

Troubleshooting

Connection Issues

If you cannot connect to PayAI:
  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 — PayAI — 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.