Developer Quickstart
Ship a USDC-accepting Express endpoint in under 5 minutes.
1. Install the SDK
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=0xYourBSCWalletAddressAIOT_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 sessionGET /aiot-pay/status/:sessionIdโ poll session statusPOST /aiot-pay/completeโ finalize a paymentGET /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
- SDK client guide โ full
AIOTShopifyClientreference - Express middleware guide โ how the mounted routes work
- Session stores โ swap the in-memory store for Redis
- Error handling โ catching the right errors in the right place
- API Reference โ auto-generated TypeDoc