TypeScript SDK for trading on Context Markets — an AI-powered prediction market platform on Base.
npm install context-markets
# or
yarn add context-markets
# or
pnpm add context-marketsimport { 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",
});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);// 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);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.
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.
- Quickstart Guide — setup, authentication, and first trade
- API Reference — full method signatures for all modules
- Best Practices — patterns, error handling, and tips
- Examples — runnable scripts for common workflows
| 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 |
MIT — see LICENSE for details.