11/Integrate
Risk checks in one line
@parity/hedera-agent-kit-plugin gives any Hedera Agent Kit v4 agent four tools to discover Parity, buy a toxicity quote, buy a guaranteed swap clearance and claim the guarantee, paid per call in USDC with a hard client-side spend cap. The source is packages/parity-plugin. It also exports ParityClient for agents that do not use Agent Kit.
Install
pnpm add @parity/hedera-agent-kit-plugin @hashgraph/hedera-agent-kit @hiero-ledger/sdkThe paying account needs a little USDC (0.0.456858 on mainnet) and must be associated with it.
import { createParityPlugin } from "@parity/hedera-agent-kit-plugin";
const parity = createParityPlugin({
gatewayUrl: process.env.PARITY_GATEWAY_URL!,
payer: { accountId: process.env.HEDERA_ACCOUNT_ID!, privateKey: process.env.HEDERA_PRIVATE_KEY! },
});
// Next to your other plugins:
const configuration = { plugins: [saucerSwapPlugin, parity], context: { accountId, mode: AgentMode.AUTONOMOUS } };Tools
| Tool | Cost | When to call | Parameters |
|---|---|---|---|
parity_get_agent_card | Free | Discovery: identity, prices, guarantee policy, track record | none |
parity_check_swap_safety | about $0.0250 | Before every swap. Returns cleared, reasons, clearanceId, expected cost, toxicity, split count, guarantee terms and ready-made swap_v2_tool params | side (SELL_HBAR = HBAR in, BUY_HBAR = USDC in), amountIn, maxSlippageBps, callerAgentId? |
parity_claim_guarantee | Free | After a cleared swap, once the Mirror Node has it (about 6 s) | clearanceId, transactionId |
parity_get_toxicity_quote | about $0.0100 | Market context: whether to trade at all, LP ranges. No guarantee | pair? |
Prices are the gateway's live prices; the figures above are the calm-market defaults. Every tool returns the Agent Kit envelope { raw, humanMessage }. Failures come back as raw.status: "ERROR" with a stable raw.code: SPEND_CAP_EXCEEDED, PAYER_REQUIRED, UNSUPPORTED_PAYMENT, PAYMENT_FAILED, HTTP_ERROR, INVALID_RESPONSE or INVALID_PARAMS. The two paid tools are listed in PARITY_PAID_TOOLS and declare toolType: "transaction", so Agent Kit policies that gate state-changing tools gate them too.
Options
| Option | Default | Meaning |
|---|---|---|
gatewayUrl | required | The Parity gateway base URL |
payer | none | { accountId, privateKey, keyType? }. Use the account that signs your swaps: the guarantee only covers swaps from the paying account. Without a payer, paid tools only report their price |
network | hedera:mainnet | Or hedera:testnet |
maxPaymentUsd | 0.25 | Hard per-call spend cap in USD |
callerAgentId | none | Default id sent with each clearance request |
fetch / client | global fetch | A custom transport, or your own ParityClient |
The spend cap
maxPaymentUsdis enforced before anything is signed, by@x402/core'sSpendControls(maxAmountPerPayment), against the price in the gateway's 402 challenge. Above the cap the call fails withSPEND_CAP_EXCEEDEDand nothing is paid, so a misbehaving gateway cannot charge more than the cap per call.- Only assets
@x402/hederacan price in USD are accepted; a challenge in HBAR is refused. - The cap is per call, not per day. Pair it with a payer account that holds a small USDC float, or an Agent Kit policy on
PARITY_PAID_TOOLS.
The guarantee, from the plugin
parity_check_swap_safetypays for a clearance. Ifcleared, execute the same trade from the paying account beforeguarantee.validUntilMs, for example withswap_v2_toolandraw.executeWith.params.- Call
parity_claim_guaranteewith the clearance id and the swap's transaction id. The answer isREFUNDED,HONOREDorREJECTED. Claiming is free, so always claim. - If the trade is not cleared, do not execute it as asked: trade smaller, split it into
recommendedSplitCountpieces, raisemaxSlippageBpsabove the expected cost, or wait.
Standalone client
import { ParityClient } from "@parity/hedera-agent-kit-plugin";
const parity = new ParityClient({ gatewayUrl, payer: { accountId, privateKey }, maxPaymentUsd: 0.1 });
const { data, clearanceId } = await parity.checkSwapSafety({ side: "SELL_HBAR", amountIn: 10, maxSlippageBps: 80 });
// execute the swap from accountId, then:
const claim = await parity.claimGuarantee({ clearanceId: clearanceId!, transactionId });Other methods: getAgentCard, getToxicityQuote, getRebalancePlan, getPrice (reads the 402 challenge without paying), getHealth, getTrackRecord, listGuarantees and getClearance.
Buyer-agent demo
examples/buyer-agent.ts is a counterparty trader built on Agent Kit with saucerSwapPlugin and this plugin. It fetches the card, buys a clearance for a tiny swap, optionally executes it, waits about 6 seconds and claims.
BUYER_ACCOUNT_ID=0.0.x BUYER_PRIVATE_KEY=... pnpm demo:buyer # pays for a clearance, never swaps
BUYER_ACCOUNT_ID=0.0.x BUYER_PRIVATE_KEY=... pnpm demo:buyer -- --execute # real 1 HBAR -> USDC swap, then claimsUse an account that is not the operator and not in BUILDER_ACCOUNT_IDS, or the payment is booked but not counted as revenue. More ways to integrate are on Agents and integrations.