Recap & Q&A
Welcome back to Day 2! Let’s recap what we learned yesterday and address any questions.
Day 1 Recap
What We Built
Yesterday, we built a market creation workflow:
HTTP Request ──▶ CRE Workflow ──▶ PredictionMarket.sol
(question) (HTTP Trigger) (createMarket)
Key Concepts Covered
| Concept | What We Learned |
|---|---|
| CRE Mental Model | Workflows, Triggers, Capabilities, DONs |
| Project Structure | project.yaml, workflow.yaml, config.json |
| HTTP Trigger | Receiving external HTTP requests |
| EVM Write | The two-step pattern (report → writeReport) |
The Two-Step Write Pattern
This is the most important pattern from Day 1:
// Step 1: Encode and sign the data
const reportResponse = runtime
.report({
encodedPayload: hexToBase64(reportData),
encoderName: "evm",
signingAlgo: "ecdsa",
hashingAlgo: "keccak256",
})
.result();
// Step 2: Write to the contract
const writeResult = evmClient
.writeReport(runtime, {
receiver: contractAddress,
report: reportResponse,
gasConfig: { gasLimit: "500000" },
})
.result();
Today’s Agenda
Today we’ll complete the prediction market with:
- Log Trigger - React to on-chain events
- EVM Read - Read state from smart contracts
- HTTP Capability - Call Gemini AI
- Complete Flow - Wire everything together
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Day 2: Market Settlement │
│ │
│ requestSettlement() ──▶ SettlementRequested Event │
│ │ │
│ ▼ │
│ CRE Log Trigger │
│ │ │
│ ┌──────────────┼───────────────────┐ │
│ ▼ ▼ ▼ │
│ EVM Read Gemini AI EVM Write │
│ (market data) (determine outcome) (settle market) │
│ │
└─────────────────────────────────────────────────────────────────┘
Common Questions from Day 1
Q: Why do we need the two-step write pattern?
A: The two-step pattern provides:
- Security: The report is cryptographically signed by the DON
- Verification: Your contract can verify the signature came from CRE
- Consensus: Multiple nodes agree on the data before signing
Q: What happens if my transaction fails?
A: Check:
- Your wallet has enough ETH for gas
- The contract address is correct
- The gas limit is sufficient
- The contract function accepts the encoded data
Q: How do I debug workflow issues?
A: Use runtime.log() liberally:
runtime.log(`[DEBUG] Value: ${JSON.stringify(data)}`);
All logs appear in the simulation output.
Q: Can I have multiple triggers in one workflow?
A: Yes! That’s exactly what we’ll do today. A workflow can have up to 10 triggers.
const initWorkflow = (config: Config) => {
return [
cre.handler(httpTrigger, onHttpTrigger),
cre.handler(logTrigger, onLogTrigger),
];
};
Quick Environment Check
Before we continue, let’s verify everything is set up:
# Check CRE authentication
cre whoami
# From the prediction-market directory
source .env
export MARKET_ADDRESS=0xYOUR_CONTRACT_ADDRESS
# Verify you have markets created (decoded output)
cast call $MARKET_ADDRESS \
"getMarket(uint256) returns ((address,uint48,uint48,bool,uint16,uint8,uint256,uint256,string))" \
0 \
--rpc-url "https://ethereum-sepolia-rpc.publicnode.com"
Ready for Day 2!
Let’s dive into Log Triggers and build the settlement workflow.