# DisputeTracker agent API examples

DisputeTracker provides paid, machine-readable Polymarket and UMA resolution intelligence.

- OpenAPI: https://disputetracker.xyz/openapi.json
- Service manifest: https://disputetracker.xyz/.well-known/agent-payments.json
- MCP: https://disputetracker.xyz/mcp
- Agent Card: https://disputetracker.xyz/.well-known/agent-card.json

## Challenge-only curl

```bash
curl -i -X POST 'https://x402.disputetracker.xyz/api/agent/stage-assessment/x402' -H 'content-type: application/json' --data '{"slugOrUrl":"example-polymarket-event"}'
curl -i -X POST 'https://mpp.disputetracker.xyz/api/agent/stage-assessment/mpp' -H 'content-type: application/json' --data '{"slugOrUrl":"example-polymarket-event"}'
```

## x402 TypeScript buyer

Install `@x402/core @x402/evm @x402/fetch viem`. This abbreviated client signs locally and refuses challenges outside its allowlist:

```ts
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const recipient = process.env.PAY_TO_ADDRESS!.toLowerCase();
const maxAmount = BigInt(process.env.MAX_PAYMENT_ATOMIC!);
const client = new x402Client()
  .register("eip155:*", new ExactEvmScheme(account))
  .registerPolicy((_version, offers) => offers.filter((offer) =>
    offer.network === "eip155:8453" &&
    offer.asset.toLowerCase() === "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" &&
    offer.payTo.toLowerCase() === recipient && BigInt(offer.amount) <= maxAmount
  ));
const paidFetch = wrapFetchWithPayment(fetch, client);
const response = await paidFetch("https://x402.disputetracker.xyz/api/agent/stage-assessment/x402", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ slugOrUrl: "example-polymarket-event" }),
});
if (!response.ok || !response.headers.has("payment-response")) throw new Error("not settled");
console.log(await response.json());
```

The hardened buyer in this repository is `scripts/agent-payments/buy-x402.ts`:

```bash
EVM_PRIVATE_KEY='<buyer-key>' PAY_TO_ADDRESS='<seller-address>' MAX_PAYMENT_ATOMIC='<policy-limit>' \
  npm run agent:buy:x402 -- --capability stage-assessment example-polymarket-event
```

## MPP TypeScript buyer

Install `mppx viem`. This abbreviated client pins the chain and recipient; production clients must also filter the challenge currency and maximum atomic amount:

```ts
import { Mppx, tempo } from "mppx/client";
import { createClient, defineChain, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const recipient = process.env.PAY_TO_ADDRESS as `0x${string}`;
const chain = defineChain({
  id: 4217, name: "Tempo Mainnet",
  nativeCurrency: { name: "USD", symbol: "USD", decimals: 18 },
  rpcUrls: { default: { http: ["https://rpc.tempo.xyz"] } },
});
const rpc = createClient({ chain, transport: http() });
const buyer = Mppx.create({
  polyfill: false,
  methods: [tempo({
    account, mode: "pull", expectedChainId: 4217,
    expectedRecipients: [recipient], getClient: () => rpc,
  })],
});
const response = await buyer.fetch("https://mpp.disputetracker.xyz/api/agent/stage-assessment/mpp", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ slugOrUrl: "example-polymarket-event" }),
});
if (!response.ok || !response.headers.has("payment-receipt")) throw new Error("not settled");
console.log(await response.json());
```

The hardened buyer in this repository adds amount and currency filtering in `scripts/agent-payments/buy-mpp.ts`:

```bash
EVM_PRIVATE_KEY='<buyer-key>' PAY_TO_ADDRESS='<seller-address>' MAX_PAYMENT_ATOMIC='<policy-limit>' \
  npm run agent:buy:mpp -- --capability stage-assessment example-polymarket-event
```

Both scripts require a buyer-side private key and a strict `MAX_PAYMENT_ATOMIC`. Do not place buyer credentials on the DisputeTracker server.
