Skip to content

Snehal707/linera-micro-bets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4,824 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒช๏ธ StormCast - Environmental Event Prediction Markets

Live Demo Built on Linera License

Decentralized prediction markets for weather and natural disaster events, built on Linera blockchain microchains.

StormCast enables users to create and bet on outcomes of real-world environmental events like hurricanes, earthquakes, tornadoes, floods, and more.


๐ŸŽฏ Live Demo

๐ŸŒ lineramicrobets.vercel.app

Note: The Vercel deployment runs in Demo Mode (localStorage) since the Linera service requires a backend server. For full on-chain functionality, run locally with linera service --port 8080.

๐Ÿš€ VPS Deployment (Coming Soon)

We're planning to deploy the Linera service to a VPS, enabling real on-chain betting directly from the Vercel frontend for all users!


โœจ Features

  • Create Markets - Anyone can create a prediction market for an upcoming weather event with a specific question and deadline
  • Place Bets - Users bet YES or NO on outcomes, with funds pooled together
  • Resolution & Payout - When the event concludes, the market resolves and winners split the pool proportionally
  • Sub-second Finality - Linera's microchain architecture enables instant transaction confirmation

๐Ÿ—๏ธ Technical Implementation

Component Technology
Smart Contract Rust with Linera SDK, MapView for bet storage, RegisterView for market state
Security Creator verification via authenticated_signer() ensures only authorized resolution
Token Integration Uses Linera's fungible token standard for seamless deposits and payouts
Frontend Next.js 14 with TypeScript, real-time market updates, responsive design

๐Ÿ“ Project Structure

linera-micro-bets/
โ”œโ”€โ”€ frontend/                    # Next.js web application
โ”‚   โ”œโ”€โ”€ app/                     # App router pages
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx            # Markets listing
โ”‚   โ”‚   โ”œโ”€โ”€ create/             # Create market page
โ”‚   โ”‚   โ”œโ”€โ”€ bet/[id]/           # Market details & betting
โ”‚   โ”‚   โ””โ”€โ”€ my-bets/            # User's betting history
โ”‚   โ””โ”€โ”€ lib/                     # Linera client & hooks
โ”‚
โ”œโ”€โ”€ examples/micro-bet/          # Linera smart contract
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ lib.rs              # Contract ABI & operations
โ”‚       โ”œโ”€โ”€ state.rs            # Bet & market data structures
โ”‚       โ”œโ”€โ”€ contract.rs         # Core betting logic
โ”‚       โ””โ”€โ”€ service.rs          # GraphQL query endpoints
โ”‚
โ””โ”€โ”€ [linera-*]/                  # Linera protocol (dependency)

๐Ÿš€ Quick Start

Demo Mode (Vercel)

Simply visit: lineramicrobets.vercel.app

Local Development

Prerequisites

1. Build Linera binaries

cargo build -p linera-storage-service -p linera-service --bins
export PATH="$PWD/target/debug:$PATH"

2. Initialize wallet with Conway testnet

linera wallet init --faucet https://faucet.testnet-conway.linera.net

3. Start Linera service

linera service --port 8080

4. Start frontend

cd frontend
npm install
npm run dev

5. Configure environment

Create frontend/.env.local:

NEXT_PUBLIC_LINERA_SERVICE_URL=http://localhost:8080
NEXT_PUBLIC_CHAIN_ID=your_chain_id
NEXT_PUBLIC_MICRO_BET_APP_ID=your_app_id

Visit http://localhost:3000 - you should see "๐Ÿ”— Linera: Connected" indicating on-chain mode!


๐Ÿ“– How It Works

Creating a Market

  1. Navigate to "Create Market"
  2. Enter the event question (e.g., "Will Hurricane X make landfall in Florida?")
  3. Set the betting deadline
  4. Submit - market is created on-chain

Placing a Bet

  1. Browse active markets on the home page
  2. Click on a market to view details
  3. Choose YES or NO
  4. Enter your bet amount
  5. Confirm - funds are locked in the pool

Resolution

  1. After the event deadline, the market creator can resolve the outcome
  2. Winners receive proportional payouts from the losing pool
  3. All transactions are recorded on Linera microchains

๐Ÿ”’ Security Note

Important: Never commit wallet.json, keystore.json, or client.db/ to version control. These files contain sensitive cryptographic keys.


๐ŸŽ“ What We Learned

  • Linera's microchain architecture enables sub-second transaction finality, perfect for time-sensitive betting
  • The View model requires careful async handling
  • Rust's type system caught many potential bugs at compile time
  • GraphQL provides a flexible API for frontend integration

๐Ÿ”ฎ Roadmap

  • VPS Deployment - Public Linera service for on-chain betting from Vercel
  • Oracle Integration - Automated weather data resolution
  • Multi-chain Support - Cross-region betting pools
  • Mobile PWA - Progressive web app for mobile users

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“„ License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments


Built with โค๏ธ for the Linera Builderthon

About

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors