Skip to content

Commit c4634f2

Browse files
authored
add prediction demo (#3205)
1 parent 1082e59 commit c4634f2

File tree

6 files changed

+355
-61
lines changed

6 files changed

+355
-61
lines changed

reports/llms-report.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"startedAt": "2025-11-21T10:34:40.607Z",
2+
"startedAt": "2025-11-21T19:58:54.423Z",
33
"siteBase": "https://docs.chain.link",
44
"sections": [
55
{
66
"section": "cre-go",
7-
"pagesProcessed": 82,
7+
"pagesProcessed": 83,
88
"outputPath": "src/content/cre/llms-full-go.txt",
9-
"bytes": 646607,
10-
"prevBytes": 646607,
11-
"deltaBytes": 0
9+
"bytes": 651940,
10+
"prevBytes": 651934,
11+
"deltaBytes": 6
1212
},
1313
{
1414
"section": "cre-ts",
15-
"pagesProcessed": 77,
15+
"pagesProcessed": 78,
1616
"outputPath": "src/content/cre/llms-full-ts.txt",
17-
"bytes": 602114,
18-
"prevBytes": 602114,
19-
"deltaBytes": 0
17+
"bytes": 607447,
18+
"prevBytes": 607441,
19+
"deltaBytes": 6
2020
},
2121
{
2222
"section": "vrf",
@@ -123,5 +123,5 @@
123123
"deltaBytes": 0
124124
}
125125
],
126-
"finishedAt": "2025-11-21T10:34:46.399Z"
126+
"finishedAt": "2025-11-21T19:58:58.682Z"
127127
}

src/config/sidebar.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,22 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
424424
section: "Templates",
425425
contents: [
426426
{
427-
title: "Building Blocks & Starter Templates",
427+
title: "Overview",
428428
url: "cre/templates",
429-
children: [
430-
{
431-
title: "Custom Data Feed Template",
432-
url: "cre/templates/running-demo-workflow",
433-
highlightAsCurrent: ["cre/templates/running-demo-workflow-ts", "cre/templates/running-demo-workflow-go"],
434-
},
435-
],
429+
},
430+
{
431+
title: "Custom Data Feed Template",
432+
url: "cre/templates/running-demo-workflow",
433+
highlightAsCurrent: ["cre/templates/running-demo-workflow-ts", "cre/templates/running-demo-workflow-go"],
434+
},
435+
],
436+
},
437+
{
438+
section: "Demos",
439+
contents: [
440+
{
441+
title: "AI-Powered Prediction Market",
442+
url: "cre/demos/prediction-market",
436443
},
437444
],
438445
},
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
section: cre
3+
title: "AI-Powered Prediction Market"
4+
date: Last Modified
5+
metadata:
6+
description: "Explore a complete end-to-end prediction market demo integrating CRE with Gemini AI and Firebase for automated, AI-powered settlements."
7+
datePublished: "2025-11-21"
8+
lastModified: "2025-11-21"
9+
---
10+
11+
import { Aside } from "@components"
12+
13+
This demo showcases a complete, end-to-end prediction market application that integrates CRE with external services. Unlike [templates](/cre/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.
14+
15+
{/* prettier-ignore */}
16+
<Aside type="caution" title="Educational Example Disclaimer">
17+
This page includes educational examples to use a Chainlink system, product, or service and is provided to
18+
demonstrate how to interact with Chainlink's systems, products, and services to integrate them into your own. This
19+
template is provided "AS IS" and "AS AVAILABLE" without warranties of any kind, it has not been audited, and it may be
20+
missing key checks or error handling to make the usage of the system, product or service more clear. Do not use the
21+
code in this example in a production environment without completing your own audits and application of best practices.
22+
Neither Chainlink Labs, the Chainlink Foundation, nor Chainlink node operators are responsible for unintended outputs
23+
that are generated due to errors in code.
24+
</Aside>
25+
26+
## GitHub Repository
27+
28+
The [repository](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo) contains complete setup instructions, including quick start guides and full end-to-end deployment steps.
29+
30+
## What this demo does
31+
32+
This demo showcases a fully automated prediction market where:
33+
34+
1. **Users create markets** by asking binary (Yes/No) questions onchain
35+
1. **Users stake ERC-20 tokens** (USDC) to make predictions
36+
1. **After the market closes**, anyone can request settlement
37+
1. **CRE automatically triggers** when it detects the settlement request event
38+
1. **Gemini AI determines the outcome** using Google search grounding for factual verification
39+
1. **CRE submits a cryptographically signed settlement** report back onchain
40+
1. **Settlement data is stored in Firestore** for audit trails and frontend display
41+
1. **Winners claim their proportional share** of the total pool
42+
43+
## Key integrations
44+
45+
This demo demonstrates several important CRE integration patterns:
46+
47+
### Event-driven workflows
48+
49+
The CRE workflow listens for `SettlementRequested` events onchain using CRE's [EVM log trigger capability](/cre/guides/workflow/using-triggers/evm-log-trigger). When a settlement is requested, the workflow automatically triggers and begins the settlement process.
50+
51+
### External AI service integration
52+
53+
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.
54+
55+
### Data persistence
56+
57+
Settlement results, including the AI's response and confidence level, are stored in [Firebase Firestore](https://firebase.google.com/docs/firestore). This creates a trail and enables the frontend to display settlement history.
58+
59+
### Cryptographic signing
60+
61+
The workflow generates cryptographically signed settlement reports that the smart contract can verify. This ensures only authorized, consensus-approved data reaches the contract.
62+
63+
### Full-stack architecture
64+
65+
The demo includes:
66+
67+
- **Smart contracts** (Solidity + Foundry): `SimpleMarket.sol` for managing prediction markets
68+
- **CRE workflow** (TypeScript): Event-driven settlement logic with AI integration
69+
- **Database** (Firebase/Firestore): Audit trail and data persistence
70+
- **Frontend** (Next.js): User interface for viewing settlement history
71+
72+
## What you'll learn
73+
74+
Exploring this demo will teach you:
75+
76+
1. **Event-driven workflow patterns**: How to use CRE's log trigger to react to onchain events in real-time
77+
1. **External service integration**: Best practices for integrating AI services like Gemini with your workflows
78+
1. **Error handling and validation**: How to validate external API responses before using them onchain
79+
1. **Data persistence patterns**: Techniques for storing workflow results in external databases
80+
1. **Full-stack dApp architecture**: How CRE fits into a complete application with smart contracts, workflows, and frontends
81+
1. **Cryptographic signing**: How CRE generates and submits cryptographically signed reports
82+
83+
## Getting started
84+
85+
The repository includes two quick start options:
86+
87+
### Option 1: Test CRE Workflow Only (Fastest)
88+
89+
Test the workflow using a pre-deployed contract and transaction. This lets you see the workflow in action without deploying anything yourself.
90+
91+
### Option 2: Full End-to-End Test
92+
93+
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.
94+
95+
See the [repository README](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo) for detailed prerequisites and setup instructions.
96+
97+
## Next steps
98+
99+
- **[Explore the repository](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo)** - Clone the demo and follow the setup instructions
100+
- **[Learn about log triggers](/cre/guides/workflow/using-triggers/evm-log-trigger)** - Understand how to build event-driven workflows
101+
- **[Explore HTTP capabilities](/cre/guides/workflow/using-http-client)** - Learn more about integrating external APIs
102+
- **[Browse templates](/cre/templates)** - Check out workflow templates you can copy and customize

src/content/cre/llms-full-go.txt

Lines changed: 108 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,10 +7114,9 @@ Yes. Once you call `runtime.Rand()` and get a `*rand.Rand` object, you can reuse
71147114

71157115
# CRE Templates
71167116
Source: https://docs.chain.link/cre/templates
7117-
Last Updated: 2025-11-20
7117+
Last Updated: 2025-11-21
71187118

7119-
CRE <a href="https://github.com/smartcontractkit/cre-templates" target="_blank" rel="noopener noreferrer">Templates</a> are workflow examples that help you learn CRE concepts and accelerate your development. They are curated and maintained
7120-
by Chainlink Labs, offering patterns you can use as references or starting points for your own workflows.
7119+
Templates are workflow examples you can copy and customize for your own projects. They are curated and maintained by Chainlink, offering patterns you can use as references or starting points for your own workflows.
71217120

71227121

71237122
<Aside type="caution" title="Educational Example Disclaimer">
@@ -7130,13 +7129,13 @@ by Chainlink Labs, offering patterns you can use as references or starting point
71307129
that are generated due to errors in code.
71317130
</Aside>
71327131

7133-
## Template types
7132+
## Building Blocks and Starter Templates
71347133

7135-
CRE Templates come in two flavors, each designed for different learning and development needs:
7134+
Templates are organized into two categories:
71367135

71377136
### 1. Building Blocks
71387137

7139-
Small, focused examples that teach **one concept at a time**. Each Building Block is self-contained and demonstrates a specific CRE capability or pattern. They feature minimal code, clear configuration, and are runnable locally with `cre workflow simulate`.
7138+
[Building Blocks](https://github.com/smartcontractkit/cre-templates/tree/main/building-blocks) are small, focused examples that teach **one concept at a time**. Each Building Block is self-contained and demonstrates a specific CRE capability or pattern. They feature minimal code, clear configuration, and are runnable locally with `cre workflow simulate`.
71407139

71417140
**Available Building Blocks:**
71427141

@@ -7158,7 +7157,7 @@ Small, focused examples that teach **one concept at a time**. Each Building Bloc
71587157

71597158
### 2. Starter Templates
71607159

7161-
Complete, end-to-end workflows that combine multiple capabilities and mirror real-world use cases. These templates are more comprehensive than Building Blocks and include production-like configuration, optional precompiled smart contracts, and generated bindings. They can be adapted directly into your own projects.
7160+
[Starter Templates](https://github.com/smartcontractkit/cre-templates/tree/main/starter-templates) are complete, end-to-end workflows that combine multiple capabilities and mirror real-world use cases. These templates are more comprehensive than Building Blocks and include production-like configuration, optional precompiled smart contracts, and generated bindings. They can be adapted directly into your own projects.
71627161

71637162
**Available Starter Templates:**
71647163

@@ -7183,11 +7182,9 @@ Complete, end-to-end workflows that combine multiple capabilities and mirror rea
71837182
- You're starting a new project and need a solid foundation
71847183
- You want to see how multiple CRE capabilities integrate in a real workflow
71857184

7186-
## How to access Templates
7187-
7188-
**CRE Templates Repository**
7185+
### How to access templates
71897186

7190-
All templates are available on GitHub at <a href="https://github.com/smartcontractkit/cre-templates" target="_blank" rel="noopener noreferrer">github.com/smartcontractkit/cre-templates</a>
7187+
All templates are available on GitHub at [github.com/smartcontractkit/cre-templates](https://github.com/smartcontractkit/cre-templates)
71917188

71927189
- Browse all Building Blocks and Starter Templates
71937190
- Clone or fork templates to customize them for your use case
@@ -7204,7 +7201,7 @@ Choose the right template based on where you are in your CRE journey:
72047201

72057202
| Your Situation | Recommended Action |
72067203
| ------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
7207-
| Just finished the [Getting Started guide](/cre/getting-started/overview) | Run the **Custom Data Feed** demo to see a more complex, real-world example |
7204+
| Just finished the [Getting Started guide](/cre/getting-started/overview) | Run the **Custom Data Feed** template to see a more complex, real-world example |
72087205
| Want to learn offchain writes with secrets and consensus | Clone the **`kv-store`** Building Block (AWS S3 example) |
72097206
| Need to read Chainlink Data Feeds in your workflow | Clone the **`read-data-feeds`** Building Block (onchain reads with ABIs) |
72107207
| Building a custom data feed for your protocol | Fork the **`custom-data-feed`** Starter Template and customize it |
@@ -7213,9 +7210,9 @@ Choose the right template based on where you are in your CRE journey:
72137210

72147211
## Next steps
72157212

7216-
Ready to explore templates? Here's where to go next:
7213+
Ready to explore templates?
72177214

7218-
- **[Run the Custom Data Feed Demo](/cre/templates/running-demo-workflow)** - Walk through this template with our step-by-step guide (available in Go and TypeScript)
7215+
- **[Run the Custom Data Feed Template](/cre/templates/running-demo-workflow)** - Walk through this template with our step-by-step guide (available in Go and TypeScript)
72197216

72207217
- **[Browse all templates on GitHub](https://github.com/smartcontractkit/cre-templates)** - Explore the full collection of Building Blocks and Starter Templates
72217218

@@ -7226,6 +7223,103 @@ Ready to explore templates? Here's where to go next:
72267223

72277224
---
72287225

7226+
# AI-Powered Prediction Market
7227+
Source: https://docs.chain.link/cre/demos/prediction-market
7228+
Last Updated: 2025-11-21
7229+
7230+
This demo showcases a complete, end-to-end prediction market application that integrates CRE with external services. Unlike [templates](/cre/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.
7231+
7232+
7233+
<Aside type="caution" title="Educational Example Disclaimer">
7234+
This page includes educational examples to use a Chainlink system, product, or service and is provided to
7235+
demonstrate how to interact with Chainlink's systems, products, and services to integrate them into your own. This
7236+
template is provided "AS IS" and "AS AVAILABLE" without warranties of any kind, it has not been audited, and it may be
7237+
missing key checks or error handling to make the usage of the system, product or service more clear. Do not use the
7238+
code in this example in a production environment without completing your own audits and application of best practices.
7239+
Neither Chainlink Labs, the Chainlink Foundation, nor Chainlink node operators are responsible for unintended outputs
7240+
that are generated due to errors in code.
7241+
</Aside>
7242+
7243+
## GitHub Repository
7244+
7245+
The [repository](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo) contains complete setup instructions, including quick start guides and full end-to-end deployment steps.
7246+
7247+
## What this demo does
7248+
7249+
This demo showcases a fully automated prediction market where:
7250+
7251+
1. **Users create markets** by asking binary (Yes/No) questions onchain
7252+
2. **Users stake ERC-20 tokens** (USDC) to make predictions
7253+
3. **After the market closes**, anyone can request settlement
7254+
4. **CRE automatically triggers** when it detects the settlement request event
7255+
5. **Gemini AI determines the outcome** using Google search grounding for factual verification
7256+
6. **CRE submits a cryptographically signed settlement** report back onchain
7257+
7. **Settlement data is stored in Firestore** for audit trails and frontend display
7258+
8. **Winners claim their proportional share** of the total pool
7259+
7260+
## Key integrations
7261+
7262+
This demo demonstrates several important CRE integration patterns:
7263+
7264+
### Event-driven workflows
7265+
7266+
The CRE workflow listens for `SettlementRequested` events onchain using CRE's [EVM log trigger capability](/cre/guides/workflow/using-triggers/evm-log-trigger). When a settlement is requested, the workflow automatically triggers and begins the settlement process.
7267+
7268+
### External AI service integration
7269+
7270+
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.
7271+
7272+
### Data persistence
7273+
7274+
Settlement results, including the AI's response and confidence level, are stored in [Firebase Firestore](https://firebase.google.com/docs/firestore). This creates a trail and enables the frontend to display settlement history.
7275+
7276+
### Cryptographic signing
7277+
7278+
The workflow generates cryptographically signed settlement reports that the smart contract can verify. This ensures only authorized, consensus-approved data reaches the contract.
7279+
7280+
### Full-stack architecture
7281+
7282+
The demo includes:
7283+
7284+
- **Smart contracts** (Solidity + Foundry): `SimpleMarket.sol` for managing prediction markets
7285+
- **CRE workflow** (TypeScript): Event-driven settlement logic with AI integration
7286+
- **Database** (Firebase/Firestore): Audit trail and data persistence
7287+
- **Frontend** (Next.js): User interface for viewing settlement history
7288+
7289+
## What you'll learn
7290+
7291+
Exploring this demo will teach you:
7292+
7293+
1. **Event-driven workflow patterns**: How to use CRE's log trigger to react to onchain events in real-time
7294+
2. **External service integration**: Best practices for integrating AI services like Gemini with your workflows
7295+
3. **Error handling and validation**: How to validate external API responses before using them onchain
7296+
4. **Data persistence patterns**: Techniques for storing workflow results in external databases
7297+
5. **Full-stack dApp architecture**: How CRE fits into a complete application with smart contracts, workflows, and frontends
7298+
6. **Cryptographic signing**: How CRE generates and submits cryptographically signed reports
7299+
7300+
## Getting started
7301+
7302+
The repository includes two quick start options:
7303+
7304+
### Option 1: Test CRE Workflow Only (Fastest)
7305+
7306+
Test the workflow using a pre-deployed contract and transaction. This lets you see the workflow in action without deploying anything yourself.
7307+
7308+
### Option 2: Full End-to-End Test
7309+
7310+
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.
7311+
7312+
See the [repository README](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo) for detailed prerequisites and setup instructions.
7313+
7314+
## Next steps
7315+
7316+
- **[Explore the repository](https://github.com/smartcontractkit/cre-gcp-prediction-market-demo)** - Clone the demo and follow the setup instructions
7317+
- **[Learn about log triggers](/cre/guides/workflow/using-triggers/evm-log-trigger)** - Understand how to build event-driven workflows
7318+
- **[Explore HTTP capabilities](/cre/guides/workflow/using-http-client)** - Learn more about integrating external APIs
7319+
- **[Browse templates](/cre/templates)** - Check out workflow templates you can copy and customize
7320+
7321+
---
7322+
72297323
# CLI Reference
72307324
Source: https://docs.chain.link/cre/reference/cli
72317325
Last Updated: 2025-11-20

0 commit comments

Comments
 (0)