Chowkidaar

Bond-backed refunds for AI agents paying over x402 on Hedera. Merchant fails, agent gets repaid.

Chowkidaar

Created At

ETHGlobal Mumbai

Project Description

AI agents can now pay for APIs on their own using x402. But once a payment settles on Hedera it is final: if the merchant returns an error, an empty body, garbage or nothing at all, the agent's money is gone and nobody is accountable. Card payments have chargebacks. Agent payments have nothing.

Chowkidaar ("watchman") is a protection layer between the paying agent and the merchant. Merchants who want protected traffic post a USDC bond. Agents route their x402 calls through the Chowkidaar gateway instead of paying the merchant directly. Every call then goes through four stages:

  1. Policy before money moves. Eight checks run before any payment: valid agent key, agent active, merchant live, merchant on the owner's allowlist, per-call cap, daily cap, minimum merchant reputation score, and enough free bond to cover a refund. Calls above the owner's approval threshold are held until the owner approves with a fresh World ID check.

  2. Payment. The agent pays the gateway over x402 (price + 2% fee). The gateway locks price + 20% penalty from the merchant's bond, pays the merchant over x402, and calls the merchant API.

  3. Objective checks. The response is checked for HTTP status, timeout, empty body, valid JSON and the merchant's own declared JSON schema. There is no AI judgement, so every verdict can be checked and argued about.

  4. Settlement. If the checks pass, the data goes back to the agent. If they fail, the agent is refunded automatically:

  • Merchant was paid and failed: the price comes out of the merchant's bond, the bond is slashed by price + 20% penalty, all in one atomic Hedera transfer.
  • Merchant failed and was never paid: the gateway refunds the price.
  • Gateway fault: the gateway refunds price + fee.

Every outcome (delivered, refunded, held, blocked) is published as a receipt on a Hedera Consensus Service topic, so the spending log is public and tamper-evident. Merchant reputation (calls, failures, refunds, slashed amount, score) is written to Arkiv, so any agent can check a merchant before paying it. Merchants verify they are a unique human with World ID, so one person cannot keep opening new merchant accounts after their bond is slashed.

Agents can use Chowkidaar in four ways: raw x402 calls to /v1/call/:slug, plain-language requests ("get me a burger") that are routed to the best eligible merchant, an MCP server so Claude, ChatGPT or Cursor can pay through a protected agent, and a Telegram bot.

The demo runs on Hedera testnet with real USDC and twelve x402 merchants, including SkyCast (live weather) and merchants built to fail in each way the checks catch.

Limits we state openly: the bond vault is a custodial Hedera account, not a smart contract; the gateway is the witness for what the merchant returned; objective checks cannot catch valid-looking but wrong data; protection covers only calls routed through the gateway; testnet only, not audited.

How it's Made

Monorepo with npm workspaces, TypeScript throughout.

Gateway (apps/gateway): Hono on Node, Drizzle ORM with SQLite (better-sqlite3), zod validation, plus a background worker for refunds, HCS receipts and Arkiv writes. Web (apps/web): Next.js 16, React 19, Tailwind 4, TanStack Query. Every number on screen is live from the gateway or the chain.

Hedera, with no Solidity. Everything uses @hiero-ledger/sdk: AccountCreateTransaction for custodial agent wallets (ECDSA alias, auto token association), TransferTransaction for HTS USDC (0.0.429274) settlement and refunds, TopicMessageSubmitTransaction for receipts, and the mirror node REST API for balances, receipts and payment checks.

x402: we use @x402/core, @x402/hono, @x402/hedera and @x402/fetch v2.30 with the exact scheme on hedera:testnet and the Blocky402 facilitator, which also pays the network fee. The gateway is an x402 seller to agents and an x402 buyer from merchants at the same time. We use the "upfront" payment flow so money settles before the merchant is called, which gives the bond something real to protect.

Arkiv: one entity per merchant under the schema agent-payment-protection.merchant-reputation.v1, written by 0x34CBC166F6680753Dc8E3E72e8dB4E04889Da298 on the Rabdi testnet. Updates are batched per merchant, and reads are filtered by owner so nobody can publish a fake score. Reputation feeds the merchant ranking and the owner's minimum-score rule.

World ID: owners sign in with World ID (OIDC, PKCE, ID token verified against JWKS). Approving a held payment needs a fresh World ID step-up (max_age=0). Merchants prove they are a unique human with IDKit 4, verified on the server.

MCP and Telegram: an @modelcontextprotocol/sdk stdio server exposes ask, list_merchants, wallet and get_receipt, and a Telegram bot exposes the same agent.

Notable details:

  • The case A refund is a single three-party Hedera transfer: the vault pays the agent the price and pays the gateway the penalty in one atomic transaction.
  • Refunds use a transaction ID fixed before submission, and the worker checks the mirror node before retrying.
  • When a merchant times out, we cannot know from HTTP whether the payment settled, so the gateway asks the mirror node whether its USDC reached the merchant. That decides who refunds: the bond or the gateway.
  • When a 402 comes back after payment, the gateway decodes the reason from the base64 payment-required header and shows it to the user.
  • Custodial agents pay by having the gateway sign as the agent and make a real HTTP round trip through /v1/call, so they go through exactly the same policy and x402 path as external agents.
  • New merchants start ranked as if they had 4 good calls out of 5, and 15% of matching requests go to newcomers, so new merchants can earn reputation. Their bond already covers any refund, so this is safe.
  • 66 gateway tests (vitest) cover the money rules, objective checks, policy, auth and ranking, plus a mock facilitator for UI work without funded keys.

On chain (testnet): HCS topic 0.0.11329161; a three-party refund with bond slash is transaction 0.0.6825454-1793909547-261933222.

background image mobile

Join the mailing list

Get the latest news and updates

Chowkidaar | ETHGlobal