A Solana program where two players lock SOL and bet on whether a city's temperature will be above or below a threshold by a deadline. Temperature data is fetched from Open-Meteo via Switchboard On-Demand oracles.
Built to learn Switchboard custom oracle feeds on Solana devnet.
- Creator creates a bet — picks a city, a temperature threshold, a direction (above/below), a deadline, and locks SOL
- Challenger joins the bet — takes the opposite side and locks the same amount of SOL
- Anyone calls
update_feedafter the deadline to fetch the latest temperature from Switchboard - Anyone calls
settle_bet— the program reads the oracle account on-chain, determines the winner, and pays out the vault
- Mumbai (0)
- Delhi (1)
- Bangalore (2)
git clone https://github.com/mahelikaa/stake-weather.git
cd stake-weather
npm install
cd app
npm install
cp .env.example .envFill in .env:
RPC_URL=https://devnet.helius-rpc.com/?api-key=YOUR_HELIUS_API_KEY
CREATOR_KEYPAIR=/path/to/creator-keypair.json
CHALLENGER_KEYPAIR=/path/to/challenger-keypair.json
anchor build --ignore-keys
cargo test--ignore-keys builds against the program ID in the source (Asn5...) instead of a locally generated keypair, so the compiled .so matches the deployed program and the tests.
Uses LiteSVM — runs the compiled Solana program in-process, no validator needed.
cd app
# 1. Creator creates a bet
npx ts-node create_bet.ts
# 2. Challenger joins
npx ts-node join_bet.ts
# 3. Wait for the deadline, then update the feed
npx ts-node update_feed.ts
# 4. Wait a few seconds for the feed update to confirm, then settle
sleep 5 && npx ts-node settle_bet.ts
# Cancel a bet before anyone joins (creator only)
npx ts-node cancel_bet.tsDeployed on Solana devnet: Asn5AeENGV3LMtZKjf3sWectSeFKif2Ea5FZD3E8Lxc5
- Anchor 0.32.1
- Switchboard On-Demand 0.13.0
- Open-Meteo for weather data
- Helius RPC for devnet
- LiteSVM for testing