Back to Hub
CREATED BY CHAINLINK LABS

Prediction Market (Data Feeds)

Full prediction market lifecycle with market creation, resolution using Chainlink Data Feeds, and dispute management.

Get the template
cre init --template=prediction-market-ts
View on GitHub

What This Template Does

This template implements the full prediction market lifecycle using three CRE workflows that share a single PredictionMarket smart contract:

  1. Market Creation (Cron, hourly) โ€” Creates new binary prediction markets with configurable strike prices and expiration times
  2. Market Resolution (Cron, every 10 minutes) โ€” Checks expired markets and resolves them using the Chainlink BTC/USD Data Feed
  3. Dispute Management (LogTrigger) โ€” Listens for DisputeRaised events and re-evaluates outcomes with fresh price data

Key Technologies:

  • CRE (Chainlink Runtime Environment) โ€” Multi-workflow orchestration with DON consensus
  • Chainlink Data Feeds โ€” Deterministic BTC/USD price resolution
  • LogTrigger + Cron โ€” Event-driven disputes with periodic creation and resolution

How It Works

Market Creation

Market Resolution

Dispute Management


Project Structure

prediction-market-ts/
โ”œโ”€โ”€ contracts/          # Shared contracts and bindings
โ”œโ”€โ”€ market-creation/    # Workflow 1: Create markets
โ”œโ”€โ”€ market-resolution/  # Workflow 2: Resolve expired markets
โ””โ”€โ”€ market-dispute/     # Workflow 3: Handle disputes

Getting Started

1 Install dependencies
cd contracts && bun install && cd ..
cd market-creation && bun install && cd ..
cd market-resolution && bun install && cd ..
cd market-dispute && bun install && cd ..
2 Run tests
cd market-creation && bun test && cd ..
cd market-resolution && bun test && cd ..
cd market-dispute && bun test && cd ..
3 Simulate workflows

Market Creation:

cre workflow simulate market-creation --target staging-settings

Market Resolution:

cre workflow simulate market-resolution --target staging-settings

Dispute Management (requires a transaction that emitted DisputeRaised):

cre workflow simulate market-dispute --target staging-settings \
  --non-interactive \
  --trigger-index 0 \
  --evm-tx-hash <TX_THAT_EMITTED_DISPUTE_RAISED> \
  --evm-event-index 0

Broadcast any workflow to write on-chain:

cre workflow simulate market-creation --target staging-settings --broadcast
4 Deploy your own contract

A demo contract is pre-deployed on Sepolia at 0xEb792aF46AB2c2f1389A774AB806423DB43aA425.

To deploy your own with Foundry:

forge create src/PredictionMarket.sol:PredictionMarket \
  --broadcast --private-key $PRIVATE_KEY \
  --rpc-url https://ethereum-sepolia-rpc.publicnode.com \
  --constructor-args \
    0x15fc6ae953e024d975e77382eeec56a9101f9f88 \
    0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 \
    86400

Constructor arguments:

  • Forwarder: 0x15fc6ae953e024d975e77382eeec56a9101f9f88
  • Price Feed: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 (BTC/USD on Sepolia)
  • Dispute Window: 86400 (24 hours in seconds)

Customization

  • Use a different asset โ€” Deploy with a different priceFeed address (e.g., ETH/USD: 0x694AA1769357215DE4FAC081bf1f309aDC325306)
  • Change market duration โ€” Update durationSeconds in market-creation/config.staging.json
  • Change resolution frequency โ€” Update schedule in market-resolution/config.staging.json
  • Change dispute window โ€” Deploy a new contract with a different disputeWindow arg

For full details, see the TypeScript README on GitHub.

Get the latest Chainlink content straight to your inbox.