Bet2Gether is a learning project on Ethereum Sepolia (October–November 2025): binary prediction rounds settled by Chainlink services. Players bet ETH on whether a Chainlink price feed will close above or below a target by a deadline. Chainlink Automation triggers settlement, payouts are time-weighted (earlier bets carry more weight), and a round creator who wins can receive an ERC-1155 collectible whose tokenId is picked by Chainlink VRF; a Tenderly Web3 Action, signing with my own key, requests that mint.
The payout has a known bug that leaves part of every pool locked in the contract: read Known bugs before relying on the numbers below.
To explore the live demo, you need a browser wallet (MetaMask works) funded with Ethereum Sepolia ETH — grab some free from the faucet below. No local setup required.
- Open the live demo.
- Connect a wallet on Ethereum Sepolia.
- Create a round (pick a Chainlink feed, target price, side, duration), or bet on an active round.
- After the deadline, Chainlink Automation resolves the round; winners pull their payout with Claim Rewards (see Known bugs for what that payout is).
Need testnet ETH? Sepolia Faucet
Prediction markets are interesting as a coordination problem only when settlement is credibly neutral. Two common designs sit in tension with that goal:
- Operator-settled markets. An admin or off-chain keeper picks the price, calls
resolve(), and decides who gets paid. The value proposition of trust-minimized outcomes then rests on trusting that one entity. - Permissionless on-chain markets without a keeper. Somebody still has to trigger resolution. If users do it, settlement is gameable (winners delay, losers grief). If a single bot does it, the trust assumption shifts back to that operator.
Reward distribution can introduce a second trust hole: random rewards driven by block.hash, block.timestamp, or admin-picked tokenIds are predictable or manipulable, especially by miners/validators or the operator themselves.
Bet2Gether is an experiment in that direction. Resolution is triggered by Chainlink Automation and priced by a Chainlink feed, and the collectible's tokenId comes from Chainlink VRF. Two pieces still depend on me: as the owner I can disable a price feed, and the reward mint is requested by a Tenderly action holding my minter key (see Known bugs).
Once a round opens, its outcome depends on the price feed and the deadline; the collectible's tokenId depends on the VRF response. Rounds go from Active to Resolved.
- Deterministic resolution.
PredictionPool._resolveRoundreadsAggregatorV3Interface.latestRoundData()for the round's allow-listed feed and compares it toround.target. Decimals are normalized to 1e18 and non-positive answers revert. The price is the one current when Automation runs, not at the deadline, and its age (updatedAt) is not checked. - Autonomous execution.
PredictionPoolimplementsAutomationCompatibleInterface.checkUpkeepreturns the IDs of rounds whose deadline has passed;performUpkeepre-checks each ID, resolves the due rounds in one batch and emitsPredictionPool_RoundResolved. No user has to callresolve(). - Time-weighted bets.
getBetWeightscales each bet by((round.end - bet.time) * 1e18) / (round.end - round.start), so an earlier bet weighs more than a late one. A winner's payout ispool × playerWeight / getTotalWeight(), where the total includes the losing side's weight too, so winners together do not receive the whole pool (see Known bugs). - Pull payments with CEI + reentrancy guard.
claimRewardmarksbet.claimed = trueand emits before the external ETH transfer, and is protected by OpenZeppelin'snonReentrant. - VRF-picked collectible.
PredictionPoolTokenis an ERC-1155 minted only viaVRFConsumerBaseV2Plus. ThetokenId = randomWord % I_MAX_TOKEN_IDis computed insidefulfillRandomWords, so which collectible a winner gets cannot be predicted from on-chain state. Requests are stored, and unknown or already fulfilled requests are refused. - Off-chain reward bridge.
PredictionPoolnever calls the token. A Tenderly Web3 Action (web3-actions/actions/predictionPoolActions.ts) listens forPredictionPool_RoundResolvedand, whencreatorIsWinner == true, callsPredictionPoolToken.mint(creator)with a key that holdsMINTER_ROLE. It reads only the firstRoundResolvedevent of a transaction and logs a failure without retrying.
The round creator picks a Chainlink feed, target price, side, and duration. Their bet is the first one in.
A second player joins on the opposite side. Time-weighted bookkeeping is updated on each bet.
When the deadline hits, checkUpkeep flags the round and Chainlink Automation calls performUpkeep. The contract reads the price feed, picks the winning side, and emits PredictionPool_RoundResolved.
If the round creator was on the winning side, the Tenderly Web3 Action requests an ERC-1155 mint for them. VRF picks the tokenId.
Tenderly execution log confirming the off-chain bridge fired:
Winners claim from the Claim Rewards tab. Payouts are pool × playerWeight / totalWeight, where totalWeight sums both sides (see Known bugs).
Two contracts on Sepolia, an off-chain Tenderly Action that turns resolution events into a mint call, and a Next.js client wired up through wagmi/viem.
Rounds move from Active toward Resolved via Automation. _resolveRound reads the feed for settlement.
A Tenderly Web3 Action listens for PredictionPool_RoundResolved. When the configured logic applies (e.g. round creator is a winner), it calls PredictionPoolToken.mint(to). VRF fulfillment performs _mint.
flowchart TB
subgraph upperLane[" "]
direction LR
user[Player]
subgraph poolBox[PredictionPool]
direction TB
createRound[createRound]
betOn[betOn]
claimReward[claimReward]
resolveRound[_resolveRound]
end
automation[Chainlink Automation]
priceFeed[Chainlink Price Feed]
end
tenderly[Tenderly Web3 Action]
subgraph tokenBox["PredictionPoolToken ERC-1155"]
direction TB
mintFn[mint]
fulfillRnd[fulfillRandomWords]
end
vrf[Chainlink VRF]
randomNft[Random NFT]
user -->|"address _feed, uint256 _target,<br/>BetSide _betSide, uint256 _duration,<br/>msg.value"| createRound
user -->|"uint256 _roundId, BetSide _betSide,<br/>msg.value"| betOn
user --> claimReward
claimReward -.->|"ETH payout"| user
automation -->|"resolve at deadline"| resolveRound
resolveRound --> priceFeed
priceFeed -->|"price"| resolveRound
resolveRound -.->|"RoundResolved event"| tenderly
tenderly -->|"if creator won"| mintFn
mintFn --> vrf
vrf --> fulfillRnd
fulfillRnd --> randomNft
| Pattern | Rationale |
|---|---|
| Checks-Effects-Interactions (CEI) | In claimReward, internal state (e.g. claimed) is updated before the external ETH transfer (PredictionPool). |
| Reentrancy guard | nonReentrant on claimReward only (PredictionPool). |
| Defensive upkeep | performUpkeep re-checks that each round is due, so bogus performData cannot resolve a round early or twice. |
| Non-deterministic rewards | Chainlink VRF v2.5 delivers a verifiable random word via callback; tokenId = _randomWords[0] % I_MAX_TOKEN_ID maps it into the valid ERC-1155 range, so the collectible's identity is unpredictable until the response arrives on-chain (PredictionPoolToken). |
| Layer | Technologies |
|---|---|
| Smart contracts | Solidity ^0.8.13, Foundry (build, test, script), OpenZeppelin (Ownable, AccessControl, ReentrancyGuard, ERC1155) |
| Oracle middleware | Chainlink Automation, Chainlink Price Feeds, Chainlink VRF v2.5 |
| Off-chain orchestration | Tenderly Web3 Actions, Alchemy RPC + WebSockets |
| Frontend | Next.js 16 (App Router), React 19, TypeScript, Tailwind CSS 4, Radix UI, shadcn/ui |
| Web3 client | wagmi v2, viem, RainbowKit |
| State and tables | TanStack Query v5, TanStack Table, React Context (rounds/bets) |
| Forms | React Hook Form + Zod |
| Quality | Foundry tests + coverage, ESLint, GitHub Actions CI (.github/workflows/foundry-tests.yml) |
65 Foundry tests: 46 on PredictionPool (including time-weight edge cases such as a last-second bet in a 365-day round) and 19 on PredictionPoolToken. CI runs forge test -vvv on every push and PR to main/develop (.github/workflows/foundry-tests.yml). No test claims a payout with bets on both sides, which is how the payout bug went unnoticed.
Coverage from the committed be/lcov.info. Branch coverage shows how much of the conditional branching ran under tests, not how complete the tests are.
| Contract | Lines | Branches | Functions |
|---|---|---|---|
| PredictionPool | 88.9% | 77.8% | 95.0% |
| PredictionPoolToken | 85.7% | 25.0% | 87.5% |
cd be && forge install
cd be && forge test --gas-report
cd be && forge coverage| Contract | Address |
|---|---|
| PredictionPool | 0x51A0a7561dEbA056C1cDF5aB4c369Db686c77EF6 |
| PredictionPoolToken | 0xddd3c73caE8541FC6Ea119C1BffC5B6547D33eCf |
Etherscan: PredictionPool · PredictionPoolToken.
Set ALCHEMY_SEPOLIA_RPC_URL, PRIVATE_KEY, and ETHERSCAN_API_KEY in be/.env. Allow-listed feeds and VRF parameters live in be/script/Constants_PredictionPool.sol and be/script/Constants_PredictionPoolToken.sol.
cd be
forge script script/PredictionPoolScript.s.sol \
--rpc-url $ALCHEMY_SEPOLIA_RPC_URL --broadcast --verify
forge script script/PredictionPoolTokenScript.s.sol \
--rpc-url $ALCHEMY_SEPOLIA_RPC_URL --broadcast --verifyAfter deployment, fund the Chainlink Automation upkeep registered for PredictionPool and the VRF subscription configured for PredictionPoolToken.
cd fe && pnpm install && pnpm devfe/.env requires NEXT_PUBLIC_ETH_SEPOLIA_ALCHEMY_HTTP_URL, NEXT_PUBLIC_ETH_SEPOLIA_ALCHEMY_WS_URL, and NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID. Network config: fe/app/_config/wagmi.ts.
After deploying the contracts, sync ABIs and addresses in fe/app/_contracts/.
The action source is web3-actions/actions/predictionPoolActions.ts and the trigger spec is web3-actions/tenderly.yaml. Configure the Tenderly project secrets PRIVATE_KEY (the address holding MINTER_ROLE on PredictionPoolToken) and RPC_URL_KEY, then deploy:
cd web3-actions && tenderly actions deploy- Payout locks part of the pool.
claimRewardcomputespool × playerWeight / getTotalWeight(), andgetTotalWeightsums the weights of both sides. Winners together receive onlypool × winnersWeight / allWeight; the rest stays in the contract. Example: A bets 1 ETH above, B bets 1 ETH below at the same time, and "above" wins: A gets 1 ETH, and B's 1 ETH stays locked. A round with no winning bets locks the whole pool. There is no refund or sweep. Fix: divide by the winning side's weight, and add a refund path for one-sided rounds. - The owner can freeze resolution. Disabling a price feed (
toggleAllowPriceFeed) makes rounds on that feed revert when resolved;performUpkeepresolves due rounds in one batch, so one revert blocks every due round. - Unbounded loops.
checkUpkeepscans every round ever created andclaimRewardloops over every player, so gas grows with use until Automation or claims run out of gas. - The reward mint depends on an off-chain bot. The Tenderly action (my key, with
MINTER_ROLE) handles only the firstRoundResolvedevent per transaction and logs failures without retrying.
- Price at resolution time. The round settles on the feed's latest answer when Automation runs, which can be after the deadline, and the answer's age is not checked.
- Rounding dust from the weight math stays in the contract.
- Unused states.
NotStartedandEndedexist in the round enum but are never kept: a round goes from Active to Resolved.
- L2 convergence. Deploy to Arbitrum or Optimism (or similar) to compare settlement and UX cost vs Sepolia/L1-style usage.
- Fix the payout. Divide by the winning side's weight and refund one-sided rounds (see Known bugs).
- On-chain reward path. Replace the Tenderly-triggered minting with a call from
PredictionPool, so no off-chain key is needed. - Bounded loops. Track due rounds and claim per player instead of scanning every round and player.
Built solo by Siegfried Bozza, Full-Stack Web3 Engineer (Foundry · Solidity · Chainlink · React · Next.js), October–November 2025.






