PredictionLabs

Getting Started

Install and configure the PredictionLabs TypeScript SDK.

The PredictionLabs TypeScript SDK provides a complete client for interacting with the protocol. Built on viem.

Install

npm install @predictionlabs/sdk

Quick Start

import { createPublicClient, createWalletClient, http } from "viem";
import { polygon } from "viem/chains";
import { PredictionLabsClient } from "@predictionlabs/sdk";

const publicClient = createPublicClient({
  chain: polygon,
  transport: http(),
});

const client = new PredictionLabsClient({
  publicClient,
  addresses: {
    factory: "0x...",     // MarketFactory address
    orderBook: "0x...",   // OrderBook address
    treasury: "0x...",    // Treasury address
    negRiskAdapter: "0x...", // NegRiskAdapter address
    umaResolver: "0x...",   // Optional
    kalshiResolver: "0x...", // Optional
    polymarketResolver: "0x...", // Optional
  },
});

// Read a market
const market = await client.getMarket("0x...");
console.log(market.resolved, market.deadline);

// Check if trading is open
const trading = await client.isTrading("0x...");

With a Wallet (for writes)

import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0x...");
const walletClient = createWalletClient({
  chain: polygon,
  transport: http(),
  account,
});

const client = new PredictionLabsClient({
  publicClient,
  walletClient,
  addresses: { /* ... */ },
});

// Create a market
const conditionId = await client.createMarket(
  "Will ETH hit $10k by Dec 2026?",
  2,         // binary (YES/NO)
  1767225600n, // deadline timestamp
  "0x...",   // resolver address
);

// Approve USDC for trading
await client.approveUsdc(addresses.orderBook);

// Place a buy order: YES at $0.65, 100 shares
const orderId = await client.placeBuyOrder(
  conditionId,
  0,         // outcome 0 = YES
  650_000n,  // $0.65 in USDC decimals
  100_000_000n, // 100 shares
);

Fee Estimation

// Estimate a BuyVsBuy fill
const estimate = client.estimateFillBuyVsBuy(
  650_000n, // order 0 price
  100_000_000n, // order 0 remaining
  400_000n, // order 1 price
  100_000_000n, // order 1 remaining
);
console.log(estimate.fillAmount, estimate.fee, estimate.surplus);

Safety Checks (for frontends)

// Check if resolver is trusted
const trusted = await client.isTrustedResolver(conditionId, [
  "0x...", // UMA resolver
  "0x...", // Kalshi resolver
]);

// Check if Kalshi market is linked
const linked = await client.isKalshiLinked(conditionId);

// Check if past deadline (danger zone)
const pastDeadline = await client.isPastDeadline(conditionId);

On this page