AIOT Payment x402 is in public beta. Install the skill for your AI agent.
QuickstartFor Developers

Developer Quickstart

Ship a USDC-accepting Express endpoint in under 5 minutes.

1. Install the SDK

$npm install @aiot/shopify-x402

The package is ESM-only and targets Node 18 or later. Make sure your package.json has "type": "module" or import it from a .mjs file.

2. Set environment variables

export AIOT_API_KEY=your_api_key
export MERCHANT_WALLET=0xYourBSCWalletAddress

AIOT_API_KEY is issued by the AIOT backend and authenticates your merchant with the facilitator. MERCHANT_WALLET is the BSC address where settled USDC will land.

3. Mount the Express middleware

import express from 'express'
import { createAIOTPaymentRoutes } from '@aiot/shopify-x402/middleware/express'
 
const app = express()
app.use(express.json())
 
app.use(
  createAIOTPaymentRoutes({
    aiotApiKey: process.env.AIOT_API_KEY!,
    merchantWallet: process.env.MERCHANT_WALLET!,
    // Shopify fields are empty for non-Shopify use:
    shopifyAccessToken: '',
    shopifyStoreDomain: '',
    // BSC Testnet defaults โ€” change to 56 for mainnet
    chainId: 97
  })
)
 
app.listen(3000, () => {
  console.log('Listening on http://localhost:3000')
})

The middleware mounts four routes under /aiot-pay:

  • POST /aiot-pay/checkout โ€” create a checkout session
  • GET /aiot-pay/status/:sessionId โ€” poll session status
  • POST /aiot-pay/complete โ€” finalize a payment
  • GET /aiot-pay/pay/:sessionId โ€” serve the payment page HTML

4. Create a checkout

curl -X POST http://localhost:3000/aiot-pay/checkout \
  -H "Content-Type: application/json" \
  -d '{"items":[{"title":"Demo product","price":"1.00","quantity":1}]}'

Expected response:

{
  "sessionId": "a7e9b2โ€ฆ",
  "paymentPageUrl": "/aiot-pay/pay/a7e9b2โ€ฆ",
  "usdcAmount": "1000000",
  "fiatTotal": "1.00",
  "expiresAt": 1738000000000
}

5. Open the payment page

open http://localhost:3000/aiot-pay/pay/<sessionId>

The page walks the payer through wallet connection, BSC chain switching, EIP-712 signing, and polling until the facilitator settles the payment on-chain.

Tip

Sessions expire after 30 minutes. Poll /aiot-pay/status/:sessionId from your frontend so the UI can react to completed, failed, or expired states without reloading.

Next steps