AI-Powered Prediction Market

This demo showcases a complete, end-to-end prediction market application that integrates CRE with external services. Unlike templates that are meant to be copied and customized, this demo is designed to be explored and studied to understand what's possible with CRE.

GitHub Repository

The repository contains complete setup instructions, including quick start guides and full end-to-end deployment steps.

What this demo does

This demo showcases a fully automated prediction market where:

  1. Users create markets by asking binary (Yes/No) questions onchain
  2. Users stake ERC-20 tokens (USDC) to make predictions
  3. After the market closes, anyone can request settlement
  4. CRE automatically triggers when it detects the settlement request event
  5. Gemini AI determines the outcome using Google search grounding for factual verification
  6. CRE submits a cryptographically signed settlement report back onchain
  7. Settlement data is stored in Firestore for audit trails and frontend display
  8. Winners claim their proportional share of the total pool

Key integrations

This demo demonstrates several important CRE integration patterns:

Event-driven workflows

The CRE workflow listens for SettlementRequested events onchain using CRE's EVM log trigger capability. When a settlement is requested, the workflow automatically triggers and begins the settlement process.

External AI service integration

The workflow sends the market question to Google's Gemini AI with search grounding enabled. Gemini searches the web to determine the factual outcome and returns a result with a confidence score.

Data persistence

Settlement results, including the AI's response and confidence level, are stored in Firebase Firestore. This creates a trail and enables the frontend to display settlement history.

Cryptographic signing

The workflow generates cryptographically signed settlement reports that the smart contract can verify. This ensures only authorized, consensus-approved data reaches the contract.

Full-stack architecture

The demo includes:

  • Smart contracts (Solidity + Foundry): SimpleMarket.sol for managing prediction markets
  • CRE workflow (TypeScript): Event-driven settlement logic with AI integration
  • Database (Firebase/Firestore): Audit trail and data persistence
  • Frontend (Next.js): User interface for viewing settlement history

What you'll learn

Exploring this demo will teach you:

  1. Event-driven workflow patterns: How to use CRE's log trigger to react to onchain events in real-time
  2. External service integration: Best practices for integrating AI services like Gemini with your workflows
  3. Error handling and validation: How to validate external API responses before using them onchain
  4. Data persistence patterns: Techniques for storing workflow results in external databases
  5. Full-stack dApp architecture: How CRE fits into a complete application with smart contracts, workflows, and frontends
  6. Cryptographic signing: How CRE generates and submits cryptographically signed reports

Getting started

The repository includes two quick start options:

Option 1: Test CRE Workflow Only (Fastest)

Test the workflow using a pre-deployed contract and transaction. This lets you see the workflow in action without deploying anything yourself.

Option 2: Full End-to-End Test

Deploy your own contracts, create markets, request settlements, and run the workflow end-to-end. This gives you complete hands-on experience with all components.

See the repository README for detailed prerequisites and setup instructions.

Next steps

Get the latest Chainlink content straight to your inbox.