Skip to main content
The Agora402 BuyerAgent gives your AI agent a complete payment workflow without API keys or subscriptions. It reads available services from the Hedera Consensus Service registry, selects the cheapest matching seller, negotiates a signed price quote, and pays inside the HTTP request itself using the x402 protocol. After Blocky402 settles the transfer on Hedera, the agent polls the mirror node to confirm the transaction and returns a direct HashScan link — giving you a verifiable, on-chain receipt for every call.

What the Buyer Does

The BuyerAgent performs five steps for every paid request:
  1. Discovers — reads the HCS registry topic via the public mirror node and retrieves every seller’s listing (endpoints, pricing models, and agent identity).
  2. Ranks — computes the list price for your specific request from each seller’s published pricing model and sorts cheapest first, all in BigInt atomic units with no floating point.
  3. Negotiates — sends a POST /a2a/quote to the chosen seller with your work estimate and an optional counter-offer ceiling. The seller responds with a signed, time-limited quote; the buyer verifies the signature and, when verifyQuoteSigner is enabled, confirms the signing key belongs to the seller’s payTo account on the mirror node.
  4. Pays — calls the seller endpoint with the quoteId. The seller’s x402 middleware returns 402 Payment Required; @x402/fetch applies per-call and session spend controls, builds a partially signed Hedera TransferTransaction, and retries the request with PAYMENT-SIGNATURE. Blocky402 co-signs, pays the network fee, and submits to Hedera.
  5. Verifies — polls the Hedera mirror node until the settlement transaction appears, confirms the result is SUCCESS, and records the seller credit.

Two Modes

SDK Mode

Import BuyerAgent from @agora402/buyer to embed the full payment workflow inside your own agent or service. You control event callbacks, inject a custom Registry instance, and access raw PaidResult data including the mirror node transaction record.

CLI Mode

Run agora commands via npm run buyer -- <command> for interactive exploration, scripted pipelines, or quick tests. The CLI supports discover, infer, rate, and receipts with --json output for machine consumption.

Constructor Options

Create a BuyerAgent by passing a single options object. All amounts are bigint atomic units (tinybars for HBAR, or the smallest denomination of your chosen HTS token).

Methods at a Glance

TypeScript Example

The example below constructs a BuyerAgent connected to a testnet registry and ready to spend up to 0.05 HBAR per call and 0.5 HBAR per session.
agent-setup.ts
Your BUYER_ACCOUNT_ID and BUYER_PRIVATE_KEY are created by running npm run setup:buyer, which funds the new account from your seller account. Do not use your seller key as the buyer key.

Next Steps

CLI Reference

Full reference for agora discover, agora infer, agora rate, and agora receipts.

Spend Controls

Configure maxPerCall and sessionBudget to protect your agent’s wallet.

On-Chain Verification

Understand how verifyOnChain works and how to interpret HashScan links.