Skip to content

Bet AI is a next-generation decentralized prediction market built on Hedera Hashgraph, integrating AI-driven confidence signals, news sentiment analysis, and autonomous market behavior.

Notifications You must be signed in to change notification settings

suryansh00001/BetAI

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

52 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ Bet AI โ€” Hedera-Powered AI Prediction Market

License Hedera AI Agent Status

Built for ETHGlobal 2025 Hackathon โ€” integrating AI-driven decision-making with Hedera-based decentralized prediction markets.


๐Ÿงญ Overview

Bet AI is a next-generation decentralized prediction market built on Hedera Hashgraph, integrating AI-driven confidence signals, news sentiment analysis, and autonomous market behavior.

The platform allows oracles to create and resolve markets, while users can place bets on outcomes. An embedded AI agent continuously analyzes market data, news context, and social sentiment to assist or even autonomously act on behalf of users.


๐Ÿง  How It Works

๐Ÿ”น 1. Oracle-Driven Market Creation

The oracle (admin) can post prediction questions (e.g., โ€œWill BTC cross $70k by next week?โ€) via the smart contract using the function:

addQuestion(string question, string[] outcomeNames, uint256 endTime)

This creates a new prediction market on the Hedera Testnet (chainId 296, 0x128).

๐Ÿ”น 2. User Betting

Users can browse live markets and place bets using HBAR. The HBAR amount is converted to tinybars before contract execution.

Hbar.from(amountHBAR).toTinybars();

They place their bet via:

placeBet(uint256 questionId, uint256 outcomeIndex, uint256 amount) payable;

๐Ÿ”น 3. AI Confidence Generation (Predict Output Page)

After a bet is placed, the backend AI agent (powered by Gemini, OpenAI, and DeepSeek) generates a confidence score โ€” a probability distribution indicating the AIโ€™s estimated likelihood of each outcome.
The Predict Output Page visualizes this signal with explanations, recent news context, and sentiment insights.

๐Ÿ”น 4. Resolution and Hedera Settlement

Once the event concludes, the oracle calls:

resolveMarket(uint256 questionId, uint256 winningOutcome);

The contract automatically distributes winnings to correct bettors on the Hedera Testnet.

๐Ÿ”น 5. Autonomous Mode (AI Trading)

Beyond manual prediction, Bet AI offers an autonomous mode, where the AI agent manages wallet funds and executes buy/sell/hold operations based on signal strength and backtesting data. This turns Bet AI into a hybrid prediction-trading platform.


๐Ÿงฉ Architecture Overview

image
Frontend (React + Vite + Tailwind CSS)
โ”‚
โ”œโ”€โ”€ User Dashboard โ€” Shows bets, profit/loss, and AI confidence charts
โ”œโ”€โ”€ Prediction Market โ€” Lists active questions and betting options
โ””โ”€โ”€ Predict Output โ€” AI analysis + autonomous actions
โ”‚
Backend (Flask + Python)
โ”‚
โ”œโ”€โ”€ /api/news-context โ€” Fetches news sentiment using NewsAPI
โ”œโ”€โ”€ /api/generate-signal โ€” Produces AI confidence using LLMs (Gemini, OpenAI, DeepSeek)
โ””โ”€โ”€ /api/agent-chat โ€” Chat interface for the Hedera AI Agent
โ”‚
Smart Contract (Hedera Parimutuel Market)
โ”‚
โ””โ”€โ”€ HBAR-based parimutuel contract for transparent payouts

๐Ÿ”— Integrations

Envio

We leverage Envio's real-time blockchain indexing infrastructure to provide instant access to prediction market data without overloading our frontend with constant RPC calls. Here's how it powers BetAI:

When smart contract events fire on Hedera โ€” whether it's a BetPlaced, QuestionAdded, MarketResolved, or WinningsClaimed โ€” Envio's indexer automatically captures and structures this data through custom event handlers. Instead of polling the blockchain repeatedly or managing complex state synchronization, we simply query Envio's GraphQL API to fetch exactly what we need.

Why does this matter? Because real-time data access is critical for a prediction market:

  • Lightning-fast UI updates โ€” Users see new bets, market resolutions, and winnings instantly without refresh delays or stale data.
  • Scalable queries โ€” No need to scan thousands of blocks or replay transaction history. Envio's indexed database handles complex aggregations and filters effortlessly.
  • Developer-friendly GraphQL API โ€” Our frontend fetches structured data with precise queries like "show me all bets for question #5" or "get the total pool for each outcome" in milliseconds.
  • Network efficiency โ€” Instead of hammering Hedera's RPC endpoints with redundant calls, we offload heavy lifting to Envio's infrastructure, keeping our app fast and our API limits safe.

The indexer runs continuously in the background, listening to our ParimutuelPredictionMarket contract on Hedera Testnet (chain ID 296). Event handlers in EventHandlers.js process each event and store normalized entities like BetPlaced, MarketResolved, etc., which are then queryable through GraphQL. This architecture ensures that BetAI remains responsive, data-accurate, and ready to scale as more users place bets and markets grow.

Hedera

We use three key features of the Hedera blockchain: Smart Contracts, the Hedera Agent Kit, and Hedera's native speed and finality.

Smart Contracts: At the core of BetAI is our ParimutuelPredictionMarket contract deployed on Hedera Testnet. When an oracle creates a prediction market (e.g., "Will BTC hit $70K by next week?"), they call addQuestion() on-chain, establishing the outcomes, end time, and betting parameters. Users then place bets by invoking placeBet() with HBAR, which is converted to tinybars and locked into the contract's pool. Once the event concludes, the oracle resolves the market via resolveMarket(), determining the winning outcome. Winners can then claim their proportional share of the total pool using claimWinnings(). This makes the entire betting lifecycle transparent, immutable, and trustless โ€” no centralized intermediary can manipulate results or withhold funds.

Hedera Agent Kit: Beyond manual betting, BetAI features an AI-powered autonomous agent built with the Hedera Agent Kit and LangChain integration. This agent doesn't just analyze markets โ€” it can execute blockchain operations on behalf of users. Through natural language commands like "Place a 10 HBAR bet on outcome 0 for question 1," the agent translates user intent into actual contract calls using ContractExecuteTransaction. The Hedera Agent Kit provides pre-built tools for querying account balances, transaction history, and contract state, while our custom placeBetTool handles bet placement logic. This enables autonomous trading mode, where the AI evaluates confidence signals, news sentiment, and backtesting results to make strategic bets without manual intervention โ€” turning BetAI into a hybrid prediction-trading platform.

Speed and Finality: Hedera's consensus mechanism delivers near-instant finality (typically 3-5 seconds), meaning bets are confirmed, markets are resolved, and winnings are claimed without the agonizing wait times of traditional blockchains. This is critical for time-sensitive prediction markets where odds shift rapidly and users expect immediate feedback. Additionally, Hedera's low and predictable fees (fractions of a cent per transaction) ensure that even small bets remain economically viable, unlike Ethereum-based markets where gas fees can exceed the bet itself.

Together, these features ensure that BetAI delivers not just decentralized betting and AI-driven insights, but also real-time responsiveness, transparent on-chain settlement, and autonomous execution capabilities โ€” all powered by Hedera's enterprise-grade infrastructure.


โš™๏ธ Environment Variables

๐Ÿ–ฅ๏ธ Frontend (frontend/.env.local)

VITE_MY_ACCOUNT_ID=0.0.xxxxxxx
VITE_MY_PRIVATE_KEY=<Ed25519 DER or ECDSA key>

๐Ÿง  Backend (backend/.env)

NEWS_API_KEY=0c17b412e22846c6b1ce4cd63d5d9fb4
GROQ_API_KEY=<your_groq_key>
HEDERA_ACCOUNT_ID=0.0.xxxxxxx
HEDERA_PRIVATE_KEY=<private_key>

๐Ÿ”— Backend Endpoints

Method Endpoint Description
POST /api/news-context Fetch contextual market news
POST /api/generate-signal Generate AI-based market confidence
POST /api/agent-chat Chat interface with Hedera AI agent

๐Ÿ’ป Run Commands (Windows)

Frontend

cd d:\ETHGlobal\frontend
npm install
npm run dev

Backend

cd d:\ETHGlobal\backend
pip install -r requirements.txt
python index.py

๐Ÿงฉ Troubleshooting

Issue Cause / Fix
INVALID_SIGNATURE Ensure correct key type (Ed25519 vs ECDSA)
process is not defined Use import.meta.env.VITE_* variables
Circuit breaker open Wait 60โ€“120s and retry (Hashio throttle)
No context returned Ensure NEWS_API_KEY is valid

๐Ÿ”’ Security Notes

  • Never commit .env files to version control.
  • Frontend keys are for development only โ€” use a server-side signer for production.
  • Admin tab is visible to all but only oracles can resolve markets.

๐Ÿ“Š Dashboard Metrics

KPI Source Description
Net Profit Local store + backend Tracks AI & user bets
Trade Count Local logs Per user/session
PnL Chart Chart.js Tracks performance over time
News Context Backend API Aggregated from NewsAPI + Twitter

๐Ÿงฉ Project Structure

d:\ETHGlobal
โ”œโ”€ frontend
โ”‚  โ”œโ”€ package.json
โ”‚  โ”œโ”€ vite.config.js
โ”‚  โ”œโ”€ .env.local                 (VITE_MY_ACCOUNT_ID, VITE_MY_PRIVATE_KEY)
โ”‚  โ”œโ”€ public
โ”‚  โ”‚  โ””โ”€ index.html
โ”‚  โ””โ”€ src
โ”‚     โ”œโ”€ main.jsx
โ”‚     โ”œโ”€ App.jsx
โ”‚     โ”œโ”€ contracts
โ”‚     โ”‚  โ””โ”€ config.js            (HEDERA_CONTRACT_ID, chainId, RPC)
โ”‚     โ”œโ”€ contexts
โ”‚     โ”‚  โ”œโ”€ WalletContext.jsx
โ”‚     โ”‚  โ””โ”€ HashConnectContext.jsx
โ”‚     โ”œโ”€ components
โ”‚     โ”‚  โ”œโ”€ Header.jsx
โ”‚     โ”‚  โ”œโ”€ PredictionGrid.jsx
โ”‚     โ”‚  โ””โ”€ ResolveTab.jsx
โ”‚     โ”œโ”€ lib
โ”‚     โ”‚  โ”œโ”€ dashboardStore.js
โ”‚     โ”‚  โ””โ”€ hedera
โ”‚     โ”‚     โ””โ”€ placeBet.js
โ”‚     โ””โ”€ pages
โ”‚        โ”œโ”€ Home.jsx
โ”‚        โ”œโ”€ Dashboard.jsx
โ”‚        โ”œโ”€ PredictionMarket.jsx
โ”‚        โ””โ”€ PredictOutput.jsx
โ”‚
โ”œโ”€ backend
โ”‚  โ”œโ”€ index.py                   (Flask app: /api/news-context, /api/generate-signal, /api/agent-chat)
โ”‚  โ”œโ”€ start_server.py
โ”‚  โ”œโ”€ news.py                    (NewsAPI helper functions)
โ”‚  โ”œโ”€ requirements.txt
โ”‚  โ””โ”€ .env                       (NEWS_API_KEY, GROQ_API_KEY, HEDERA_*)
โ”‚
โ””โ”€ contracts
   โ””โ”€ PredictionMarket.sol

๐Ÿงฎ Smart Contract Interface

addQuestion(string question, string[] outcomeNames, uint256 endTime) // owner-only
placeBet(uint256 questionId, uint256 outcomeIndex, uint256 amount) payable
resolveMarket(uint256 questionId, uint256 winningOutcome) // owner-only
getMarket(uint256 questionId)

Contract ID: 0.0.7100616
EVM Address: 0x53f25235e70380605ea794da768d9662ab72ad52
Network: Hedera Testnet (chainId 296 / 0x128)


๐Ÿงฑ Tech Stack

Layer Technology
Frontend React, Vite, Tailwind CSS
Backend Python (Flask)
Blockchain Hedera Hashgraph
Smart Contracts Solidity (ParimutuelPredictionMarket)
AI Models Gemini, OpenAI, DeepSeek
News & Sentiment NewsAPI, Twitter API
Deployment Hedera SDK + IPFS (optional)

๐Ÿงพ License

This project is licensed under the MIT License.


๐Ÿ‘ฅ Contributors

Name Role
Suryansh Garg AI & Blockchain Developer
Jaydeep Pokhariya AI & Blockchain Developer
Vivek Maurya AI & Blockchain Developer
Jinesh Bansal AI & Blockchain Developer

โšก AI-driven intelligence meets blockchain transparency โ€” empowering decentralized, data-backed prediction markets with autonomous trading capabilities.

About

Bet AI is a next-generation decentralized prediction market built on Hedera Hashgraph, integrating AI-driven confidence signals, news sentiment analysis, and autonomous market behavior.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 76.5%
  • Python 17.7%
  • Solidity 3.2%
  • HTML 1.9%
  • Other 0.7%