Skip to main content
This example demonstrates how a merchant backend can accept intentMandate (SD-JWT-VC) tokens from an agent and process a payment via the Delegare SDK. The source code is available in the examples/express-checkout directory of the Delegare repository.

Overview

  1. Setup Buyer: The merchant creates a setup session for the user.
  2. Authorization: The user completes the setup via the Delegare UI, generating an Intent Mandate.
  3. Checkout: The AI agent sends the Intent Mandate to the merchant’s /api/checkout endpoint.
  4. Execution: The merchant backend uses @delegare/sdk to charge the mandate.

Merchant Backend (Node.js)

Running the Demo locally

If you have the Delegare repository cloned, you can run the interactive demo:
Then, in a separate terminal, run the buyer setup script:
This script will give you a setup URL. Open it, complete the flow in Sandbox mode, and the script will automatically output a curl command you can use to test the checkout!

Testing the x402 API Paywall

This example also demonstrates the @delegare/x402 middleware, which automatically protects the /api/premium-data endpoint and charges AI agents $0.05 per request.
⚠️ IMPORTANT: x402 requires Crypto (USDC) The x402 protocol settles natively on-chain. To test this flow, your “Buyer” account MUST have a Crypto Wallet connected.
  1. Ensure you are testing from a separate “Buyer” account (not your Merchant account). Use an incognito window if necessary.
  2. Ensure that Buyer account has connected a Coinbase Smart Wallet (or similar) loaded with testnet USDC and ETH on Base Sepolia.
  3. When you run node setup-buyer.js to generate the mandate, you must authorize the Crypto spending option, which will require you to actively sign a transaction on the Sepolia blockchain in your wallet. (A Fiat-only mandate will fail the x402 check!)
You can test this flow locally using the provided x402.js script! Simply add your Crypto-authorized mandate token to your .env file:
Then run the script:
The script uses delegare.fetch() to automatically detect the 402 Payment Required challenge, authorize the $0.05 USDC payment via the Delegare SDK, and retry the request to securely fetch the premium data!
💡 Note on Dashboard Tracking: If you provide a raw 0x address in MERCHANT_USDC_WALLET inside your .env that is not connected to your Merchant profile, the payment will succeed on-chain, but the Delegare backend won’t know it belongs to you! It will be recorded under a generic “Web3 Merchant” and won’t appear in your dashboard. To see x402 transactions in your dashboard, make sure you connect that exact USDC wallet via the Payment Methods tab first.