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
TheBuyerAgent performs five steps for every paid request:
- Discovers — reads the HCS registry topic via the public mirror node and retrieves every seller’s listing (endpoints, pricing models, and agent identity).
- 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.
- Negotiates — sends a
POST /a2a/quoteto 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, whenverifyQuoteSigneris enabled, confirms the signing key belongs to the seller’spayToaccount on the mirror node. - Pays — calls the seller endpoint with the
quoteId. The seller’s x402 middleware returns402 Payment Required;@x402/fetchapplies per-call and session spend controls, builds a partially signed HederaTransferTransaction, and retries the request withPAYMENT-SIGNATURE. Blocky402 co-signs, pays the network fee, and submits to Hedera. - 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 aBuyerAgent 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 aBuyerAgent 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.