← Protocols
Polymarket
01Description

Largest onchain prediction market. Markets are tokenized via Gnosis Conditional Tokens (CTF) and traded against an offchain CLOB that settles onchain in USDC.e on Polygon, with UMA optimistic oracle resolution.

02Best for
  • 01prediction market frontends
  • 02event-driven trading bots
  • 03market discovery / odds widgets
  • 04portfolio dashboards
  • 05research and analytics on event probabilities
03Install
  • pnpm add @polymarket/clob-client
  • pip install py-clob-client
04Environment variables
VariableScopeDescription
POLYMARKET_PRIVATE_KEYServerPrivate key of the Polygon EOA that will sign CLOB orders (server-only — never ship to the browser).
POLYMARKET_FUNDER_ADDRESSServerPolygon address holding USDC.e that funds the CTF position (often a Polymarket proxy / Safe — required for L2 / browser-wallet sig types).
POLYMARKET_API_KEYServerDerived CLOB API credential set (key/secret/passphrase) returned by `createOrDeriveApiKey` — store the trio together.
NEXT_PUBLIC_POLYMARKET_GAMMA_URLClientBase URL for the public Gamma markets API. Defaults to https://gamma-api.polymarket.com — override only for staging.
05Prompt snippet
Use Polymarket for onchain prediction markets on Polygon. For market discovery (no auth) call the Gamma API at `https://gamma-api.polymarket.com/markets` and `/events` — filter by `active=true&closed=false&limit=...` and read `clobTokenIds` (the YES/NO ERC-1155 CTF token IDs). For order books and trading hit the CLOB at `https://clob.polymarket.com`: instantiate `new ClobClient(host, chainId=137, signer, creds, signatureType, funder)` from `@polymarket/clob-client` (or `py-clob-client`), then `getOrderBook(tokenId)` / `getMidpoint(tokenId)` for prices and `createAndPostOrder({ tokenID, price, size, side })` to trade. Settle in USDC.e (bridged USDC, 6 decimals) — not native USDC — and resolve via the UMA optimistic oracle.
06Gotchas
  • Polymarket settles in USDC.e (bridged USDC, 6 decimals) on Polygon — NOT native USDC. Bridge or swap before funding orders or balances will appear empty.
  • CLOB is offchain matching with onchain settlement via the CTF Exchange contract; orders are EIP-712 signed by the funder, not the API key. Pick the right `signatureType` (0 EOA, 1 POLY_PROXY, 2 POLY_GNOSIS_SAFE) for your wallet flow or signatures will reject.
  • Markets resolve via UMA optimistic oracle — disputes can delay settlement by days or flip the outcome. Never assume `resolvedOutcome` is final until `umaResolutionStatus === 'resolved'` and the dispute window has passed.
  • Polymarket is geo-restricted to non-US users (and other blocked jurisdictions). The hosted UI blocks US IPs; if you build a public frontend you must implement equivalent geofencing or you risk CFTC action.
  • Each market is a pair of complementary CTF ERC-1155 tokens (YES + NO sum to $1). Don't treat them as ERC-20 — use the ConditionalTokens contract for redemption / merging, and remember `clobTokenIds` is an array of two strings.
  • Gamma and CLOB rate-limit aggressively without keys — cache market metadata and use websockets (`wss://ws-subscriptions-clob.polymarket.com`) for live order books instead of polling.
07Alternatives