Skip to content

contextwtf/context-sdk

Repository files navigation

Context

Context SDK

TypeScript SDK for trading on Context Markets — an AI-powered prediction market platform on Base.

npm License: MIT Discord

Install

npm install context-markets
# or
yarn add context-markets
# or
pnpm add context-markets

Quick Start

Read Market Data (no auth)

import { ContextClient } from "context-markets";

const ctx = new ContextClient();

// Search and list markets
const { markets } = await ctx.markets.list({ query: "elections", status: "active" });

// Get quotes, orderbook, oracle
const quotes = await ctx.markets.quotes(markets[0].id);
const book = await ctx.markets.orderbook(markets[0].id);
const oracle = await ctx.markets.oracle(markets[0].id);

// Simulate a trade before placing
const sim = await ctx.markets.simulate(markets[0].id, {
  side: "yes",
  amount: 10,
  amountType: "usd",
});

Place an Order (requires signer)

import { ContextClient } from "context-markets";

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

// Place a limit order: buy 10 YES contracts at 45¢
const result = await ctx.orders.create({
  marketId: "0x...",
  outcome: "yes",
  side: "buy",
  priceCents: 45,
  size: 10,
});

// Cancel it
await ctx.orders.cancel(result.order.nonce);

Wallet Setup & Deposits

// One-call setup: approves USDC + operator
await ctx.account.setup();

// Deposit USDC into Holdings contract
await ctx.account.deposit(100); // 100 USDC

// Or use gasless (no ETH needed):
await ctx.account.gaslessSetup();
await ctx.account.gaslessDeposit(100);

Create a Market

const submission = await ctx.questions.submitAndWait(
  "Will BTC close above $100k by Dec 31, 2026?"
);
const { marketId } = await ctx.markets.create(submission.questions[0].id);

Need an API key? Visit context.markets or join our Discord.

Configuration

new ContextClient({
  apiKey: "ctx_pk_...",           // Required for authenticated endpoints
  baseUrl: "https://...",         // Override API base URL
  rpcUrl: "https://...",          // Override RPC URL for on-chain reads
  signer: { privateKey: "0x..." } // Required for order signing & wallet ops
})

The SDK accepts three signer formats: a private key string, a viem Account object, or a viem WalletClient (for browser wallets).

Prices are in cents (1–99). Sizes are in contracts. The SDK maps "yes" / "no" to the correct on-chain outcome index automatically.

Documentation

Ecosystem

Package Description
context-markets TypeScript SDK for trading
context-markets-react React hooks for market data and trading
context-markets-mcp MCP server for AI agents
context-markets-cli CLI for trading from the terminal
context-skills AI agent skill files
context-plugin Claude Code plugin

License

MIT — see LICENSE for details.

About

TypeScript SDK for Context Markets V2 API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors