Privacy-Preserving Prediction Markets on Solana
Bet privately. Reveal fairly. Win transparently.
A decentralized prediction market that uses commit-reveal cryptography to prevent front-running and ensure fair betting β built for the Indie.fun Hackathon.
π Live Demo β’ π On-Chain Program β’ π Quick Start
| Feature | Description |
|---|---|
| π Private Betting | Bets are hidden using SHA-256 commitment hashes until reveal phase |
| β‘ Front-Running Protection | Commit-reveal scheme prevents miners/validators from exploiting bet information |
| π° Trustless Payouts | Winnings are distributed proportionally from PDA-controlled vaults |
| π― Simple UX | Clean interface for creating markets, placing bets, and claiming rewards |
| π Real-Time Dashboard | Track all your bets, reveals, and winnings in one place |
| π Non-Custodial | Your funds stay in smart contract vaults β no central authority |
EchoBet Pro uses a three-phase commit-reveal mechanism to ensure fair and private betting:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ECHOBET PRO FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β π PHASE 1: COMMIT π PHASE 2: REVEAL π PHASE 3: CLAIM β
β ββββββββββββββββββ ββββββββββββββββββ βββββββββββββββββ β
β β
β User places bet with After deadline, Winners claim β
β hidden commitment: user reveals: proportional β
β payouts: β
β hash(amount + outcome β’ Original outcome β
β + random_salt) β’ Secret salt payout = stake Γ β
β β’ Verified on-chain (total_pool / β
β β β winning_pool) β
β Stored on-chain Bet counted in pool β β
β (hidden from others) (YES or NO) SOL transferred β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-
π Commit Phase β Place your bet by submitting a hash of your choice + amount + secret salt. Nobody can see your bet.
-
π Reveal Phase β After the betting deadline, reveal your original bet. The smart contract verifies your hash matches.
-
π Claim Phase β Once the market is resolved, winners claim their proportional share from the prize pool.
flowchart TB
subgraph Frontend["π₯οΈ Frontend (React + Vite)"]
UI[User Interface]
WA[Wallet Adapter]
IDL[Anchor IDL]
end
subgraph Blockchain["βοΈ Solana Devnet"]
Program[EchoBet Program]
subgraph Accounts["π¦ Program Accounts"]
Market[Market PDA]
Commitment[Commitment PDA]
Vault[Vault PDA]
end
end
subgraph User["π€ User"]
Phantom[Phantom Wallet]
LocalStorage[Local Storage\n- Salt backup]
end
User --> Frontend
Phantom <--> WA
WA <--> Program
Frontend --> IDL --> Program
Program --> Accounts
LocalStorage -.->|Salt for reveal| Frontend
erDiagram
MARKET ||--o{ COMMITMENT : "has many"
MARKET ||--|| VAULT : "owns"
MARKET {
pubkey creator
pubkey oracle
u64 market_id
string question
i64 deadline
i64 reveal_deadline
enum status
u8 outcome
u64 total_pool
u64 yes_pool
u64 no_pool
u32 yes_count
u32 no_count
}
COMMITMENT {
pubkey market
pubkey user
bytes32 commitment_hash
u64 amount
u8 revealed_outcome
bytes32 revealed_salt
bool is_revealed
bool is_claimed
}
VAULT {
lamports balance
pubkey market
}
sequenceDiagram
participant U as User
participant F as Frontend
participant P as Program
participant V as Vault PDA
Note over U,V: π Phase 1: Create & Commit
U->>F: Create Market
F->>P: create_market(question, deadline)
P->>P: Initialize Market + Vault PDAs
U->>F: Place Bet (amount, YES/NO)
F->>F: Generate salt, compute hash
F->>P: commit_bet(hash, amount)
P->>V: Transfer SOL to vault
F->>F: Save salt to localStorage
Note over U,V: π Phase 2: Reveal
U->>F: Reveal Bet
F->>F: Load salt from localStorage
F->>P: reveal_bet(outcome, salt)
P->>P: Verify hash matches
P->>P: Update pool counts
Note over U,V: βοΈ Phase 3: Resolve & Claim
U->>F: Resolve Market (Oracle only)
F->>P: resolve_market(winning_outcome)
U->>F: Claim Winnings
F->>P: claim_winnings()
P->>P: Calculate proportional payout
V->>U: Transfer SOL to winner
| Technology | Purpose |
|---|---|
| Anchor 0.32.1 | Solana development framework |
| Rust | Smart contract language |
| SHA-256 | Commitment hash generation |
| PDAs | Secure account derivation |
| Technology | Purpose |
|---|---|
| React 18 | UI framework |
| TypeScript | Type safety |
| Vite 7 | Build tool |
| TailwindCSS | Styling |
| @solana/wallet-adapter | Wallet integration |
| @coral-xyz/anchor | Program interaction |
| Service | Purpose |
|---|---|
| Solana Devnet | Blockchain network |
| Vercel | Frontend hosting |
| GitHub | Version control |
| Security Feature | Implementation |
|---|---|
| Commitment Scheme | SHA-256 hash of (amount + outcome + 32-byte salt) |
| Front-Running Prevention | Bets hidden until reveal phase ends |
| PDA Vaults | Funds controlled by program, not individuals |
| Time-Locked Phases | Strict deadline enforcement on-chain |
| Oracle Authorization | Only designated resolver can set outcome |
| Duplicate Prevention | One commitment per user per market |
| Overflow Protection | Safe math on all pool calculations |
- Node.js 18+
- Rust & Cargo
- Solana CLI
- Anchor CLI 0.32.1
# Clone the repository
git clone https://github.com/TobieTom/echobet-pro.git
cd echobet-pro
# Install dependencies
npm install
cd app && npm install && cd ..# Start local validator and run tests
anchor test# Terminal 1: Start local validator
solana-test-validator
# Terminal 2: Deploy program
anchor build
anchor deploy
# Terminal 3: Start frontend
cd app
npm run devOpen http://localhost:5173 in your browser.
| Resource | Value |
|---|---|
| Program ID | HTDC5bDN6u7q1FCYnEuevztZM1ZqKcD9ujPTTLwNfTCc |
| Network | Solana Devnet |
| Live Demo | echobet-pro.vercel.app |
| Explorer | View on Solana Explorer |
- Install Phantom Wallet
- Switch to Devnet in Phantom settings
- Get devnet SOL from faucet.solana.com
- Visit echobet-pro.vercel.app
- Connect wallet and start betting!
echobet-pro/
βββ programs/
β βββ echobet_pro/
β βββ src/
β βββ lib.rs # Main program logic
β βββ state.rs # Account structures
β βββ errors.rs # Custom errors
βββ app/
β βββ src/
β βββ pages/
β β βββ Markets.tsx # Market listing
β β βββ CreateMarket.tsx
β β βββ MarketDetail.tsx
β β βββ Dashboard.tsx
β βββ components/
β βββ hooks/
β β βββ useProgram.ts # Anchor integration
β β βββ useBetStorage.ts
β βββ utils/
β β βββ commitment.ts # Hash generation
β β βββ pda.ts # PDA derivation
β βββ idl/
β βββ echobet_pro.json
βββ tests/
β βββ echobet_pro.ts # 23 comprehensive tests
βββ Anchor.toml
βββ README.md
β Creates a market (409ms)
β Commits a bet (YES) (452ms)
β Commits a bet (NO) (443ms)
β Prevents duplicate commits (201ms)
β Reveals a bet correctly (389ms)
β Rejects invalid reveal (wrong salt) (198ms)
β Rejects invalid reveal (wrong outcome) (195ms)
β Resolves market as oracle (367ms)
β Rejects unauthorized resolver (189ms)
β Claims winnings for winner (412ms)
β Rejects claim for loser (187ms)
β Rejects double claim (184ms)
... and 11 more tests
23 passing (8.2s)
- Mainnet Deployment β Launch on Solana mainnet
- Multiple Outcomes β Support markets with 3+ options
- Decentralized Oracles β Integrate Pyth/Chainlink for resolution
- Mobile App β React Native companion app
- Liquidity Pools β AMM-style market making
- Governance Token β DAO for protocol decisions
Built by TobiasBond for the Indie.fun Hackathon
This project is licensed under the MIT License - see the LICENSE file for details.
π² EchoBet Pro β Where Privacy Meets Prediction
Try the Demo β’ View Source β’ Explore On-Chain