Skip to main content

Context SDK

The Context SDK is a TypeScript client for Context Markets. It wraps the REST API and handles EIP-712 order signing, so you can read market data and place trades with a few lines of code.

Install

npm install @contextwtf/sdk
The SDK requires Node.js 18+ and is published to GitHub Packages under @contextwtf/sdk.

Quick start

Read market data (no auth)

import { ContextClient } from "@contextwtf/sdk"

const ctx = new ContextClient()

// List trending markets
const { markets } = await ctx.markets.list({ sortBy: "trending", limit: 5 })

for (const market of markets) {
  console.log(market.question)
}

// Get quotes for a market
const quotes = await ctx.markets.quotes(markets[0].id)
console.log(`Yes: ${quotes.yes.bid}¢ bid / ${quotes.yes.ask}¢ ask`)

Place an order (with signer)

You must set up your wallet before placing orders.
import { ContextClient } from "@contextwtf/sdk"

const ctx = new ContextClient({
  apiKey: process.env.CONTEXT_API_KEY!,
  signer: { privateKey: process.env.PRIVATE_KEY! as `0x${string}` },
})

// Buy 10 Yes contracts at 45¢
await ctx.orders.create({
  marketId: "0x...",
  outcome: "yes",
  side: "buy",
  priceCents: 45,
  size: 10,
})

What’s included

Pricing conventions

The SDK uses human-friendly units:
ValueFormatExample
PricesCents (1-99)45 = 45¢ = 45% probability
SizesContracts10 = 10 contracts
OutcomesString"yes" or "no"
The SDK handles all on-chain encoding (BigInts, outcome indices, TUSD decimals) internally.

Network

Currently targeting Base Sepolia testnet (chain ID 84532).
ContractAddress
Settlement0xCB6CBCb87fe36Dd48b08930867C8D1E5fDDeE251
Holdings0x3A81C17a9bf6D5d425fbF67C4BE8aA279f8F6F95
MarketFactory0x333271eB9a252F3CCc5fd9e6026B09C717Df01d5
ResolutionTimelock0x9fE68A1595C049B54b797B599dAac90A60A94F91
TUSD0xBbee2756d3169CF7065e5E9C4A5EA9b1D1Fd415e