Bet2Gether
Built Nov–Dec 2025Autonomous Chainlink Oracle-Driven Settlement









Autonomous oracle settlement
Chainlink Automation performs upkeep; pool resolves from Price Feed (Bet2Gether README).
Overview
Prediction markets only stay interesting when settlement is credibly neutral. Operator-settled designs ask you to trust whoever calls resolve and picks the price. Permissionless on-chain designs still need something to trigger resolution at the deadline — if only winners call it, timing becomes gameable; if a single bot runs it, trust shifts to that operator. Random rewards driven by block metadata or admin-picked tokenIds are easy to bias or predict.
Once a round opens, settlement and reward draws are encoded as state transitions tied to oracle inputs — no operator step after that. PredictionPool reads Chainlink Price Feeds at the deadline; Chainlink Automation calls performUpkeep; Chainlink VRF v2.5 supplies verifiable randomness for ERC-1155 reward tokenIds; a Tenderly Web3 Action can bridge resolution events to a gated mint when the round creator wins.
Technical Architecture
Bet2Gether is a small prediction-market case study on Ethereum Sepolia. Rounds resolve from an allow-listed Chainlink Price Feed when the pool's resolve step runs after the deadline — the settlement price is whatever the feed returns at resolution time, not an ad hoc admin choice. PredictionPool implements AutomationCompatibleInterface: checkUpkeep flags due rounds and performUpkeep resolves them. PredictionPoolToken mints randomized ERC-1155 collectibles via VRFConsumerBaseV2Plus; a Tenderly Web3 Action listens for PredictionPool_RoundResolved and, when configured logic applies, calls mint with MINTER_ROLE protection. The Next.js client uses wagmi, viem, Alchemy WebSockets, and RainbowKit for wallet UX and event-driven UI.
Key features
- Prediction games with oracle pricing: Players bet on crypto price movements; settlement reads Chainlink Price Feeds.
- CEI Pattern & Reentrancy Guard: In claimReward, internal state (e.g. claimed) is updated before the external ETH transfer (Checks-Effects-Interactions). nonReentrant protects claimReward.
- Atomic Settlement: _resolveRound reads the settlement price from the feed and updates round status in one execution step for that round.
- Autonomous Settlement Engine: PredictionPool implements AutomationCompatibleInterface — Chainlink Automation calls performUpkeep so eligible rounds resolve without centralized administrative control.
- Provably Fair NFT Rewards: Winning game creators receive randomized ERC-1155 NFTs using Chainlink VRF v2.5 for verifiable randomness.
- Time-Weighted Payouts: getBetWeight scales each bet by `((round.end - bet.time) * 1e18) / (round.end - round.start)` — earlier conviction earns a larger share of the pool than late-round piling-on.
- Real-Time Updates: UI reacts instantly to new games, bets, and resolutions via Alchemy WebSockets and contract event listeners (Wagmi).
- Hybrid On-Chain/Off-Chain Automation: Tenderly Web3 Actions mint NFT rewards based on on-chain events, exploring off-chain automation.
- Smart Contract Testing: Solidity contracts tested with Foundry.
- Verified Smart Contracts: Deployed to Sepolia and automatically verified on Etherscan for transparency.
Technologies Used
- Solidity + Foundry: Core game logic, payout calculations, VRF integration, and comprehensive contract testing.
- Next.js + Wagmi: Frontend framework with wallet integration and event-driven data flow.
- Chainlink Services: Price Feeds for trustless pricing, Automation for game resolution, and VRF for NFT randomness.
- Alchemy WebSockets: Live updates for new games, bets, resolutions and NFT rewards.
- OpenZeppelin: Ownable, AccessControl, ReentrancyGuard, and ERC1155 — `claimReward` reentrancy guard, MINTER_ROLE-gated mint, and the PredictionPoolToken ledger.
Challenges and Learnings
Wiring multiple Chainlink surfaces (Price Feeds, Automation, VRF) without letting any one path become a hidden admin. Real-time UI needed selective refetching and disciplined event listeners instead of polling everything. Isolating payout math, VRF callbacks, and the Tenderly bridge kept failure modes easier to reason about.
Outcome
Bet2Gether is deployed on Ethereum Sepolia with verified PredictionPool and PredictionPoolToken on Etherscan. It is a learning exercise in oracle-driven resolution, autonomous upkeep, verifiable randomness for collectibles, and a small event-driven Next.js client — not a production prediction market.
Key Metrics
- Deployment: Ethereum Sepolia — PredictionPool & PredictionPoolToken verified on Etherscan
- Sepolia addresses: PredictionPool · PredictionPoolToken
- Chainlink: Price Feeds (settlement), Automation (performUpkeep), VRF v2.5 (ERC-1155 reward randomness)
- Settlement: Price feed at deadline — not an operator-chosen number
- Real-time UI: Alchemy WebSockets + wagmi listeners
- Coverage caveat: Branch coverage measures how much branching ran under tests — not total logical completeness. README snapshot: PredictionPool ~89.5% lines / ~77.8% branches; PredictionPoolToken ~85.7% lines / ~25.0% branches (see repo for latest `forge coverage`).
Transferable patterns: Oracle-driven settlement, hybrid on/off-chain automation, event-driven UI architecture.
Known limitations
- Testnet only — Deployed on Ethereum Sepolia for experimentation, not mainnet money at risk.
- Tenderly bridge — The Web3 Action is an off-chain automation path with its own trust assumptions; minting is gated by MINTER_ROLE on PredictionPoolToken.
Roadmap
- L2 convergence — Deploy to Arbitrum, Optimism, or similar to compare settlement cost and UX vs Sepolia.
- On-chain reward path — Replace Tenderly-triggered minting with logic inside core contracts for a fully on-chain reward flow.













