This example demonstrates how a merchant backend can acceptDocumentation Index
Fetch the complete documentation index at: https://docs.delegare.dev/llms.txt
Use this file to discover all available pages before exploring further.
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
- Setup Buyer: The merchant creates a setup session for the user.
- Authorization: The user completes the setup via the Delegare UI, generating an Intent Mandate.
- Checkout: The AI agent sends the Intent Mandate to the merchant’s
/api/checkoutendpoint. - Execution: The merchant backend uses
@delegare/sdkto charge the mandate.
Merchant Backend (Node.js)
Running the Demo locally
If you have the Delegare repository cloned, you can run the interactive demo: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) TheYou can test this flow locally using the providedx402protocol settles natively on-chain. To test this flow, your “Buyer” account MUST have a Crypto Wallet connected.
- Ensure you are testing from a separate “Buyer” account (not your Merchant account). Use an incognito window if necessary.
- Ensure that Buyer account has connected a Coinbase Smart Wallet (or similar) loaded with testnet USDC and ETH on Base Sepolia.
- When you run
node setup-buyer.jsto 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!)
x402.js script!
Simply add your Crypto-authorized mandate token to your .env file:
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 inMERCHANT_USDC_WALLETinside your.envthat 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.