You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
<Asidetype="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
@@ -7114,10 +7114,9 @@ Yes. Once you call `runtime.Rand()` and get a `*rand.Rand` object, you can reuse
7114
7114
7115
7115
# CRE Templates
7116
7116
Source: https://docs.chain.link/cre/templates
7117
-
Last Updated: 2025-11-20
7117
+
Last Updated: 2025-11-21
7118
7118
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.
7121
7120
7122
7121
7123
7122
<Aside type="caution" title="Educational Example Disclaimer">
@@ -7130,13 +7129,13 @@ by Chainlink Labs, offering patterns you can use as references or starting point
7130
7129
that are generated due to errors in code.
7131
7130
</Aside>
7132
7131
7133
-
## Template types
7132
+
## Building Blocks and Starter Templates
7134
7133
7135
-
CRE Templates come in two flavors, each designed for different learning and development needs:
7134
+
Templates are organized into two categories:
7136
7135
7137
7136
### 1. Building Blocks
7138
7137
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`.
7140
7139
7141
7140
**Available Building Blocks:**
7142
7141
@@ -7158,7 +7157,7 @@ Small, focused examples that teach **one concept at a time**. Each Building Bloc
7158
7157
7159
7158
### 2. Starter Templates
7160
7159
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.
7162
7161
7163
7162
**Available Starter Templates:**
7164
7163
@@ -7183,11 +7182,9 @@ Complete, end-to-end workflows that combine multiple capabilities and mirror rea
7183
7182
- You're starting a new project and need a solid foundation
7184
7183
- You want to see how multiple CRE capabilities integrate in a real workflow
7185
7184
7186
-
## How to access Templates
7187
-
7188
-
**CRE Templates Repository**
7185
+
### How to access templates
7189
7186
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)
7191
7188
7192
7189
- Browse all Building Blocks and Starter Templates
7193
7190
- 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:
| 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 |
7208
7205
| Want to learn offchain writes with secrets and consensus | Clone the **`kv-store`** Building Block (AWS S3 example) |
7209
7206
| Need to read Chainlink Data Feeds in your workflow | Clone the **`read-data-feeds`** Building Block (onchain reads with ABIs) |
7210
7207
| 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:
7213
7210
7214
7211
## Next steps
7215
7212
7216
-
Ready to explore templates? Here's where to go next:
7213
+
Ready to explore templates?
7217
7214
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)
7219
7216
7220
7217
- **[Browse all templates on GitHub](https://github.com/smartcontractkit/cre-templates)** - Explore the full collection of Building Blocks and Starter Templates
7221
7218
@@ -7226,6 +7223,103 @@ Ready to explore templates? Here's where to go next:
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.
- **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
0 commit comments