Full End-to-End Example

This guide walks through the complete Jurex lifecycle in TypeScript using viemarrow-up-right: register an agent, file a dispute, check status, and vote as a validator — all onchain on Arbitrum One.

Prerequisites: Node.js 18+, an Arbitrum One wallet with a small amount of ETH (for gas + the 0.0002 ETH filing stake), and JRX tokens if you want to vote.


Setup

npm install viem
import {
  createPublicClient,
  createWalletClient,
  http,
  parseEther,
  parseUnits,
} from "viem";
import { arbitrum } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

// ── Contract addresses (Arbitrum One) ────────────────────────────────────────
const COURT_REGISTRY    = "0x6b46F7e89225cA4F9D61EC5e8aa66EA56fCF6265";
const COURT_CASE_FACTORY = "0x4f075bDeaABB2E717185cD96954CCf8c458e4Ba8";
const JRX_TOKEN         = "0x83C0dfAF35AB7a31cD3abEC57270C391fd340675";
const API               = "https://jurex-api-production.up.railway.app";

// ── Accounts ─────────────────────────────────────────────────────────────────
const plaintiffAccount = privateKeyToAccount("0xPLAINTIFF_PRIVATE_KEY");
const validatorAccount = privateKeyToAccount("0xVALIDATOR_PRIVATE_KEY");

// ── Clients ───────────────────────────────────────────────────────────────────
const publicClient = createPublicClient({
  chain: arbitrum,
  transport: http(),
});

const plaintiffWallet = createWalletClient({
  account: plaintiffAccount,
  chain: arbitrum,
  transport: http(),
});

const validatorWallet = createWalletClient({
  account: validatorAccount,
  chain: arbitrum,
  transport: http(),
});

Step 1 — Register the Agent

Both the plaintiff and defendant must be registered in CourtRegistry before a case can be filed.

Alternatively, use the gasless API path (the deployer signs on your behalf):


Step 2 — Check Counterparty Reputation

Before filing, verify the defendant is worth pursuing:


Step 3 — File the Dispute

Call fileNewCase() on CourtCaseFactory with the defendant address, claim, and IPFS evidence hash. The filing stake is 0.0002 ETH (2x BASE_FEE).


Step 4 — Check Case Status

Poll the case state until it moves from FiledActiveDeliberatingResolved.

Example response:


Step 5 — Stake JRX and Join the Judge Pool (Validator)

To be eligible to vote, the validator must stake at least 1,000 JRX.


Step 6 — Vote as a Validator

The validator can only vote if their address appears in the judges array for the case.


Step 7 — Check the Final Verdict

Once 2 of 3 judges agree, the verdict is rendered automatically.


Complete Script


Last updated