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

installbash
pnpm add @parity/hedera-agent-kit-plugin @hashgraph/hedera-agent-kit @hiero-ledger/sdk

The paying account needs a little USDC (0.0.456858 on mainnet) and must be associated with it.

quick startts
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

ToolCostWhen to callParameters
parity_get_agent_cardFreeDiscovery: identity, prices, guarantee policy, track recordnone
parity_check_swap_safetyabout $0.0250Before every swap. Returns cleared, reasons, clearanceId, expected cost, toxicity, split count, guarantee terms and ready-made swap_v2_tool paramsside (SELL_HBAR = HBAR in, BUY_HBAR = USDC in), amountIn, maxSlippageBps, callerAgentId?
parity_claim_guaranteeFreeAfter a cleared swap, once the Mirror Node has it (about 6 s)clearanceId, transactionId
parity_get_toxicity_quoteabout $0.0100Market context: whether to trade at all, LP ranges. No guaranteepair?

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

OptionDefaultMeaning
gatewayUrlrequiredThe Parity gateway base URL
payernone{ 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
networkhedera:mainnetOr hedera:testnet
maxPaymentUsd0.25Hard per-call spend cap in USD
callerAgentIdnoneDefault id sent with each clearance request
fetch / clientglobal fetchA custom transport, or your own ParityClient

The spend cap

  • maxPaymentUsd is enforced before anything is signed, by @x402/core's SpendControls (maxAmountPerPayment), against the price in the gateway's 402 challenge. Above the cap the call fails with SPEND_CAP_EXCEEDED and nothing is paid, so a misbehaving gateway cannot charge more than the cap per call.
  • Only assets @x402/hedera can 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

  1. parity_check_swap_safety pays for a clearance. If cleared, execute the same trade from the paying account before guarantee.validUntilMs, for example with swap_v2_tool and raw.executeWith.params.
  2. Call parity_claim_guarantee with the clearance id and the swap's transaction id. The answer is REFUNDED, HONORED or REJECTED. Claiming is free, so always claim.
  3. If the trade is not cleared, do not execute it as asked: trade smaller, split it into recommendedSplitCount pieces, raise maxSlippageBps above the expected cost, or wait.

Standalone client

ParityClientts
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.

from the repo rootbash
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 claims

Use 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.