Building Prediction Markets on Ethereum: A Complete Developer Guide
Everything you need to build a decentralized prediction market on Ethereum, from market resolution logic and AMM pricing to oracle integration and UI.
Why Prediction Markets Work On-Chain
Prediction markets are financial instruments where participants bet on the outcome of future events. The market price reflects the aggregate probability assigned by all participants to each outcome. When designed well, prediction markets are among the most accurate forecasting tools available — they aggregate dispersed information more efficiently than polls, expert panels, or traditional forecasting models.
Blockchain is the ideal substrate for prediction markets:
Censorship resistance: no central operator can remove markets on politically inconvenient questions.
Global access: anyone with a wallet participates, not just residents of permitted jurisdictions.
Transparent settlement: market resolution logic is public and auditable.
Composability: prediction market positions are tokens that can be used as collateral in DeFi protocols.
Polymarket demonstrated this at scale in 2024-2025, becoming the most cited source for real-time probability estimates for elections, geopolitical events, and macroeconomic outcomes. The technical foundation of Polymarket — conditional token framework, AMM pricing, and UMA oracle for resolution — is the blueprint for building your own prediction market.
Market Structure: Binary, Categorical, and Scalar Markets
Prediction markets have three outcome structures:
Binary markets: exactly two outcomes (YES/NO). "Will ETH exceed $10,000 before December 31, 2026?" Binary markets are the simplest to implement and most liquid because capital is concentrated in two assets.
Categorical markets: multiple discrete outcomes. "Who will win the 2026 World Cup?" Each country is a token. The sum of all outcome token prices should equal 1 (the probability of each outcome sums to 100%). Categorical markets have fragmented liquidity across many outcomes.
Scalar markets: continuous outcome ranges. "What will the ETH/USD price be on December 31, 2026?" Payouts are linear between a low and high bound based on the resolution value. More complex but enable finer-grained probability estimates.
For most projects: start with binary markets. They are simplest to implement, easiest for users to understand, and most liquid. Expand to categorical and scalar once the core infrastructure is proven.
Token representation: for binary markets, mint two tokens: YES and NO. Their combined value always equals the collateral amount (e.g., 1 USDC). A YES token worth $0.70 represents a 70% market probability. At resolution, YES token holders receive $1 per token (if YES wins) or $0 (if NO wins).
Market Creation and AMM Pricing
A prediction market needs a pricing mechanism that allows anyone to buy or sell outcome tokens at any time. Two approaches: order books and AMMs.
Order book markets (like Polymarket): users place limit orders. A central limit order book matches buyers and sellers. More capital-efficient but requires liquidity providers to actively manage orders. Off-chain order books with on-chain settlement (Polymarket's CLOB) provide the best UX.
AMM-based markets (CPMM or LMSR): a smart contract provides continuous liquidity at all times. The constant product market maker (YES_reserve * NO_reserve = k) is simple and composable. The Logarithmic Market Scoring Rule (LMSR) is an alternative with better theoretical properties for prediction markets.
CPMM implementation for binary markets:
Initialize with equal YES and NO token reserves.
Swap function: buy YES tokens by providing USDC (collateral), splitting it equally into YES and NO (minting new tokens), then selling the NO tokens back to the pool.
Price calculation: YES price = NO_reserve / (YES_reserve + NO_reserve).
The pool charges a fee (e.g., 2%) on each swap.
Liquidity provision: LPs deposit collateral and receive LP tokens proportional to their share of the pool. LPs earn fees from trading activity but are exposed to impermanent loss as the market probability moves.
Oracle Integration and Market Resolution
Market resolution is the hardest part of prediction market design. You need a mechanism to determine the correct outcome and distribute winnings accordingly.
Resolution options:
Centralized resolution: a trusted party (your team) calls a resolve(outcome) function after the event occurs. Simple but introduces counterparty risk — the resolving party can manipulate outcomes.
UMA's Optimistic Oracle: anyone can propose a resolution. If no one disputes it within a challenge period (48-72 hours), it is accepted. Disputes trigger a DVM (Data Verification Mechanism) vote where UMA token holders decide the outcome. Used by Polymarket for all market resolution.
Chainlink automation: for programmatically verifiable outcomes (e.g., ETH price at a specific timestamp), use Chainlink Price Feeds to resolve automatically without any human involvement.
Reality.eth: a decentralized oracle where anyone can answer questions for a bond. If someone provides a wrong answer and someone else corrects it (posting a higher bond), the corrector wins the original bond. This bond escalation game converges on truthful answers.
Implementation pattern for UMA integration:
Call priceIdentifier registry to register your market question.
On market expiry, call umaOracle.requestPrice() with your question and timestamp.
After the challenge period, call umaOracle.settle() and read the settled price.
Call your market.resolve(settledOutcome) to distribute winnings.
Building the Frontend and Managing Liquidity
A prediction market frontend needs three views: market discovery (browse open markets), market detail (current prices, trading history, resolution criteria), and portfolio (your open positions).
Displaying probability: show prices as percentages. A YES token at $0.67 = "67% probability of YES." Sort markets by volume, then by time to resolution, with featured markets pinned.
Trading interface: simple BUY/SELL interface for YES and NO tokens. Show the user's current position, their P&L, and the effective price they will receive (accounting for slippage). For AMM markets, show the price impact of their trade size.
Conditional token framework: Gnosis's CTF (now standard on Polygon) provides the canonical implementation of conditional tokens — ERC-1155 tokens that represent positions in prediction markets. Consider building on CTF rather than a custom token implementation for compatibility with the broader prediction market ecosystem.
Liquidity bootstrapping: fresh markets have no liquidity. Strategies to bootstrap:
Protocol-owned liquidity: deploy protocol treasury as initial AMM liquidity.
Liquidity mining: reward LPs with protocol tokens for providing liquidity to new markets.
Market maker relationships: work with professional market makers who provide two-sided liquidity in exchange for fee rebates.
Factory contract pattern: a MarketFactory contract deploys new markets deterministically. Store market parameters (question, resolution oracle, expiry, collateral token) in the factory. Emit a MarketCreated event so indexers can discover all markets. Build a subgraph or use a block explorer to power the market discovery frontend.