FlashBets

Bet. Win. Repeat!! 5-second bets on crypto predictions, no gas, instant payouts

FlashBets

Created At

ETHOnline 2025

Project Description

Flashbets is a real-time, wallet-native micro prediction market for crypto price movements. It lets anyone bet on the next short-term move of assets like BTC, ETH, and SOL and get resolved in seconds, not hours. You choose a direction, stake a small amount, wait for the round timer to finish, and instantly see if you won, how much you earned, and how it affects your profit/loss and leaderboard rank.

How it's Made

Flashbets is built as a Next.js client that communicates with a backend through WebSocket connections. It continuously fetches live price data and runs a timed betting engine entirely within the client’s state. The app integrates wallet-based authentication and uses temporary session keys to provide a smooth, low-friction user experience.

The frontend is implemented in Next.js. The core component, PredictionMarketUI, manages all the essential states of the app—this includes the connected wallet, the currently selected market (BTC, ETH, or SOL), all active and future betting rounds, and timer logic for round settlements. It also tracks user metrics such as balance, profit/loss, win rate, total staked, and total winnings. The UI displays bet history, active bets, and leaderboard data, while also pushing toast notifications for user feedback.

Stylistically, the interface combines Tailwind utility classes with custom components such as GlassCard and BackgroundFX to achieve a premium look blending a trading terminal’s precision with a game HUD’s dynamic energy. Frosted-glass cards, glowing elements, and live status badges enhance the visual feedback loop. On the right-hand panel, users see their wallet/auth state, balance, quick bet options, and live statistics. A MarketViewToggle switch allows users to alternate between betting grid mode and leaderboard mode seamlessly.

All betting logic and timing functionality are encapsulated within helper modules under @/lib/market. Key constants like REVEAL_EVERY_SECONDS define the round duration, while MIN_BET and QUICK_BETS specify stake presets. Functions like seedRounds and newRound generate and roll forward the rounds grid dynamically. The bucketFromChange helper categorizes price movement into one of four buckets — Strong Bull, Bull, Bear, or Strong Bear — while getPendingStakeTotal tracks unresolved stakes. Utility functions such as toCents, fromCents, and formatUSD maintain currency precision and formatting consistency.

The UI runs an internal interval loop that decrements the countdown timer for each active round. When a round ends, it fetches the latest price data, compares it to the previous round’s settlement price, determines the winning bucket, calculates payouts, and updates user balances, histories, and leaderboard standings. Post-settlement, the system also recalculates win count, win rate, total winnings, and P/L exposure. A contextual toast provides immediate feedback such as “Won $3.42” or “Already bet this round”.

Price data for BTC, ETH, and SOL is fetched via the custom hook usePythLatestREST. Each asset uses a canonical Pyth price ID, normalized through canonId. The current live price is displayed in the market selector and serves as the reference point for settlement logic. This external oracle-based resolution ensures fairness and transparency since outcomes are based on live market data rather than internal logic or manual input.

Flashbets maintains a persistent WebSocket connection through webSocketService. The connection state (Connected, Connecting, Disconnected) is displayed in the UI with a dynamic status indicator. Over this channel, the frontend sends structured, semantic messages such as “market/subscribe” when switching between BTC/ETH/SOL feeds, “bet/place” when placing a stake on a future round, and “wallet/connected” when a wallet is available for session association. Incoming messages from the backend follow an RPC-style format and are parsed by helpers like parseAnyRPCResponse. These include messages like AuthChallenge, AuthVerify, GetLedgerBalances, BalanceUpdate, and toast. This bidirectional structure allows the UI to update live balances, authenticate users in real time, and confirm bets instantly.

Wallet connectivity is handled through a custom React hook, useWalletViem, which wraps the viem library. It exposes account, walletClient (the signer), and connection utilities like connectWallet() and disconnect(). Once a wallet connects, an authentication handshake begins over the WebSocket channel. The frontend either generates or retrieves a cached ephemeral session key using helpers such as generateSessionKey, getStoredSessionKey, and storeSessionKey. An authentication request is built with createAuthRequestMessage, containing the user’s wallet address, session key, expiry timestamp, and access scope. The server responds with an AuthChallenge, which the client signs using createEIP712AuthMessageSigner (EIP-712 typed signing). The client then verifies through createAuthVerifyMessage. On success, the user is marked authenticated, and if a JWT is returned, it is saved via storeJWT.

This method ensures the wallet only needs to sign once per session, after which the browser can operate securely using the authorized session key. This dramatically improves UX by eliminating repeated signature prompts and keeping the betting flow frictionless.

After authentication, balances are fetched using createGetLedgerBalancesMessage, signed with the session key through createECDSAMessageSigner. The backend responds with GetLedgerBalances, containing assets such as USDC. The frontend continues listening for BalanceUpdate messages to reflect real-time changes. If authenticated, the sidebar displays live balances. Otherwise, users see a demo balance with an option to “Add $10 demo funds” to simulate betting.

The leaderboard displays performance metrics for players like Alpha, Blaze, Nexus, and You. Each round’s settlement updates profit/loss standings in real time, visualized through the LeaderboardCombinedChart component. This fosters a sense of competition and engagement, critical for retention, and makes even the demo experience lively and interactive.

Flashbets successfully replicates the speed and polish of an exchange-grade UI while maintaining decentralized identity principles. Its key innovation lies in signed session keys — the wallet signs once to authorize a temporary key, which is then reused for fast authenticated actions. The app also includes a demo/judge mode, enabling users without wallets to experience the full gameplay loop — from betting and resolution to leaderboard updates — using virtual balances. This helps new users understand the platform instantly, without blockchain setup friction.

The frontend stack includes React and Next.js with Tailwind-style glass UI components. The data feed is a Pyth-style live oracle for BTC, ETH, and SOL. The round engine handles timed rounds, bucket classification, payouts, P/L tracking, and logging. The WebSocket bridge enables real-time messages for authentication, ledger updates, bet placement, and notifications. Wallet integration uses viem with EIP-712 signing for secure, one-time authorization. Session handling uses ephemeral session keys with optional JWT for persistent state. The leaderboard provides real-time visualization to enhance competitive play.

Overall, Flashbets brings together real-time price data, wallet-native authentication, instant settlement logic, and social gameplay mechanics into a single cohesive system. It feels fast, fair, and multiplayer, transforming crypto prediction from a slow, manual experience into a live, gamified betting terminal.

background image mobile

Join the mailing list

Get the latest news and updates