Back to the red bull cans

Built inside TermiX's dashboard, plus my own demo merchants

Agent payments: x402 and AP2 on BNB Chain

AI assistants that pay with crypto on their own, using x402 and AP2 on BNB Chain

ShelvedSep 2025–Jan 2026web3-merchant on GitHub

Video in the works

Agent payments: x402 and AP2 on BNB Chain

The recorded AP2 checkout: an agent shops, MetaMask signs, the payment settles on chain.

About the project

Demos of AI assistants that buy things and pay with crypto by themselves, mostly on BNB Chain, built on two new payment standards: Coinbase's x402 and Google's AP2. BNB Chain had no token that works with x402's fee-free payments, so I adapted one and deployed it on BNB Chain testnet and mainnet. An assistant could browse a shop, fill a cart and pay through MetaMask, a crypto wallet, even without paying network fees.

AI agents will need to pay for things on their own. In late 2025 two standards for that appeared: Google's AP2, which defines signed "mandates" for what an agent is allowed to buy, and Coinbase's x402, which lets a payment travel with a web request. I built working demos of both.

Inside TermiX's dashboard, an AI agent could browse a merchant's API, build a cart, and pay in crypto through MetaMask, including a gasless option. A merchant joins with just a wallet and an OpenAPI spec. Later I built a small agent marketplace on Base, where a chat agent sells research reports for USDC, with spend limits.

How it works

  1. Intent

    The user tells the agent what to buy. That becomes an intent mandate.

  2. Cart

    The agent calls the merchant's API through tools, builds a cart, and the merchant signs it.

  3. Sign

    The user signs the payment mandate in MetaMask as EIP-712 typed data.

  4. Pay

    Either a normal transfer from MetaMask, or gasless: the user signs an authorization, and a facilitator checks and settles it.

  5. Confirm

    The transaction hash goes back to the agent automatically, and the order completes.

Under the hood

AP2 module
Inside TermiX's NestJS dashboard: 28 tools for the shopping agent, merchant, credentials provider and payment processor.
Merchants
A watch store API with a full OpenAPI spec, and a NestJS merchant selling tokens with EIP-712 endpoints.
Chain
ethers and viem, MetaMask on Sepolia and BNB Chain testnet and mainnet, and an EIP-3009 token adapted for BNB Chain.
Marketplace
USDC on Base mainnet, a merchant agent over MCP, and a wallet UI.

What I did

  • Studied Google's AP2 and wrote my own guides on how mandates, MCP and MetaMask fit together
  • Ported AP2's mandate types (intent, cart, payment) from Python to TypeScript and built an AP2 module in the TermiX dashboard, with 28 demo tools for the shopping agent, merchant, credentials provider and payment processor
  • Wired in real MetaMask: the user signs the payment mandate as EIP-712 typed data, then sends the transfer. First on Sepolia, then BNB Chain testnet and mainnet with network switching
  • Stored AP2 sessions with Prisma and built a 4-step merchant wizard: give a wallet and an OpenAPI URL, and the merchant's endpoints become tools the agent can call
  • Built a demo merchant API: 15 watches, carts that expire, tax and coupons, shipping rates, orders, and a full OpenAPI spec with Swagger UI
  • Built a second merchant in NestJS that sells BNB Chain tokens with EIP-712 mandate endpoints, then cut it back to a lean MVP
  • Added BNB Chain support to a local copy of x402. BNB Chain has no gasless USDC, so I adapted an EIP-3009 token from Circle's and Coinbase's reference code and deployed it with Hardhat
  • Added an x402 gasless mode: the user signs an authorization, the merchant checks the cart, amount and stock, then a facilitator verifies and settles it
  • Live USD to BNB pricing from CoinGecko, with a one-minute cache and fallback rates
  • An agent marketplace on Base with USDC: a chat agent that sells research reports under spend limits, with a merchant agent over MCP and a wallet UI
  • Set up Coinbase's x402 facilitator example for Base mainnet, with a USDC test script

What was new

  • AP2's mandate model: an intent, then a cart signed by the merchant, then a payment signed by the user
  • EIP-712 typed-data signing and EIP-3009 gasless transfers, and how an x402 facilitator splits verify and settle
  • Writing, deploying and verifying a Solidity token with Hardhat
  • Letting any merchant plug in through an OpenAPI spec that turns into agent tools

Problems I hit, and how I fixed them

  1. The payment mandate was rebuilt on every tool call with a new id and timestamp, so the MetaMask signature never matched and the agent looped forever.

    Fix Two-phase signing: store the first typed data in the session and check against it.

  2. The merchant nickname was being passed as the merchant address, so ethers tried an ENS lookup and failed.

    Fix Pass the merchant's real wallet address.

  3. The frontend treated Wei as ETH and inflated the amount to send.

    Fix Keep Wei on the backend and convert only for MetaMask.

  4. Users had to paste the transaction hash back into the chat.

    Fix Replay the payment tool automatically with the hash once MetaMask returns it.

  5. USDC rejected signatures with "FiatTokenV2: invalid signature".

    Fix Match the EIP-712 domain name exactly to the token contract.

  6. The checkout showed a 0x000 wallet, $0.00, and invisible text in dark mode.

    Fix Use the real merchant wallet, live prices and proper dark-mode styles.

Timeline

  1. Sep 2025Research notes on AP2 and MetaMask
  2. Oct 2025AP2 module in the TermiX dashboard, demo merchants, MetaMask payments
  3. Oct 2025x402 token deployed on BNB Chain testnet and mainnet
  4. Nov 2025x402 gasless mode added to the AP2 flow, on a branch
  5. Dec 2025–Jan 2026Agent marketplace on Base with USDC

Screenshots

Screenshots in the works

Real screens from Agent payments: x402 and AP2 on BNB Chain go here.

To be clear

AP2 is Google's protocol and x402 is Coinbase's. I built integrations and demos on top of them. The token contracts are adapted from Circle's and Coinbase's reference code, not written from scratch.