🪙

RITUAL FLIP DOCS

A provably fair coin flip game on the Ritual testnet. Powered by drand verifiable randomness via Ritual's 0x0801 HTTP precompile. Session wallet architecture — sign once, flip without popups forever.

✅ Live on Ritual Testnet 🎲 drand Verifiable Randomness 🔑 Session Wallet — No Popups ⚡ ~10–30s Settlement 🎮 Demo Mode ⚠ Experimental
🎮

HOW TO PLAY

1
Get RITUAL tokens from the faucet: faucet.ritualfoundation.org.
You need RITUAL to bet and to cover gas for your game wallet.
2
Connect your MetaMask wallet.
The app auto-adds Ritual Testnet (Chain ID 1979). No manual setup needed.
3
Sign once to create your Game Wallet.
MetaMask shows a single signature request — no gas spent. This derives a private, persistent game wallet from your signature. Same signature = same wallet every time. Your private key never leaves your browser.
4
Deposit RITUAL to your Game Wallet.
Click ⬇ DEPOSIT in the menu — send RITUAL via MetaMask or copy the game wallet address to send manually. Recommended: 0.05–0.1 RITUAL to start.
5
Pick HEADS or TAILS, enter your bet, press START.
No MetaMask popup — the game wallet signs flips automatically. Result arrives in ~10–30s via drand randomness. Win → 1.96× returned. Lose → bet gone.
6
Withdraw anytime.
Click ⬆ WITHDRAW in the menu to send your remaining game wallet balance back to your main MetaMask wallet — no popup needed.
🎮
Try Demo Mode first: Click PLAY DEMO on the main screen to test with 1,000 fake RITUAL — no wallet, no tokens, no signing. All features work in demo mode.

FEATURES

Session Wallet

🔑 Game Wallet (Session Wallet)

Derived deterministically from your MetaMask signature. Sign once — play forever with no popups per flip. Your private key is computed in-browser and never stored or sent anywhere.

⬇️ Deposit / ⬆️ Withdraw

Deposit RITUAL from MetaMask to your game wallet in one click. Withdraw your remaining balance back to MetaMask anytime — no confirmation popup on withdrawal.

🔋 Auto RitualWallet Top-Up

Each flip costs a small precompile fee (~0.000044 RITUAL) drawn from your RitualWallet credit. The app automatically tops it up when credit falls below 0.002 RITUAL — completely invisible to you.

🌐 Domain-Bound Signature

The signing message includes the site domain, so a game wallet derived on this site cannot be replicated by a phishing copy. Your wallet is safe even if you sign a look-alike message elsewhere.

Betting Tools

½× / 2× / MAX Presets

Quick bet size buttons to halve, double, or max out your current bet in one click.

🔄 Martingale Mode

Automatically doubles your bet after every loss. Resets to base bet on a win. Toggle in the bet panel. Persists across reloads.

⚡ Auto-Bet (Advanced)

Set a fixed flip count, Stop Loss %, and Take Profit %. Auto-bet runs all flips continuously — no clicking needed.

📊 Stats Panel

Full session history: flip count, total wagered, net PnL, win rate, and a scrollable flip log. Saved to localStorage — survives reloads.

UI & Social

🌙 Dark / Light Mode

Full theme toggle, persists in localStorage.

🌄 Background Themes

Click the background to cycle: Day ☀️ → Night 🌙 → Winter ❄️.

𝕏 Share Card

After each flip, share a 1200×630px card to X with your PnL, stats, and a pepe image. Copy, download, or post directly.

📺 Live Activity Feed

Real-time feed of all flips on the contract — address, won/lost, amount. Polls every 1 second.

Vault

🏦 Live Vault Balance

Shows real-time vault balance and effective max bet in the menu. Updated every 30 seconds.

🤖 Autonomous Vault Manager

A Scheduler contract runs autoManage() every ~12 min — adjusts maxBet to 5% of current vault and auto-pauses if vault drops below 50% of its initial value.

⚙️

GAME MECHANICS

WIN
×1.96
Receive 1.96× your bet back
LOSE
−100%
Lose your entire bet
💡
House edge: 2% — built into every payout. True flip odds are 50/50.
payout = (bet − fee) × 2  where  fee = bet × 2%
Fee stays in the vault on every flip regardless of win or lose.
BETWIN → RECEIVEWIN NETLOSE NET
0.0010.00196+0.00096−0.001
0.0050.0098+0.0048−0.005
0.010.0196+0.0096−0.01
Bet Limits
Minimum Bet
0.0005 RITUAL
Maximum Bet
5% of vault (dynamic, on-chain enforced)
House Fee
2%
Settlement Time
~10–30s (drand fetch via Ritual TEE)
Randomness — drand via 0x0801
🎲
Result is determined by drand — a public, distributed randomness beacon run by EPFL, Cloudflare, and others:

1. Your flip() tx is sent from your game wallet.
2. Ritual's 0x0801 HTTP precompile fetches drand.cloudflare.com/public/latest inside a TEE (Trusted Execution Environment) — the result is cryptographically attested.
3. Result = keccak256(drand_body, player, block) % 2 — neither the house, player, nor validators can predict or influence it.
4. Fulfilled replay: your transaction is re-executed with the drand result injected — result and payout settle atomically in the same block.

Unlimited concurrent players — each flip is independent with no shared state or queue.
💸
Per-flip cost breakdown (game wallet pays, invisible to user):
• Gas: ~0.0002 RITUAL per flip
• drand precompile fee: ~0.000044 RITUAL (drawn from RitualWallet credit)
• Working capital reserved: ~0.003 RITUAL during tx (returned after settlement)
A 0.05 RITUAL deposit covers 200+ flips with room to spare.
📜

SMART CONTRACT

Network
Ritual Testnet
Chain ID
1979
Contract Address (CoinFlipV6b)
0xc87eb197024d93e188ec5ef9bf70a3fd1b13f94b  [View on Explorer ↗]
Language
Solidity 0.8.20
Deploy Block
15,776,364
Key Functions
🎯
flip(bool choice) payable — called by game wallet. Fetches drand via 0x0801, computes result, pays winner. All in one fulfilled-replay transaction.
🤖
autoManage(uint256 index) — Scheduler callback (~every 12 min). Adjusts maxBet to 5% of vault. Pauses/unpauses based on vault floor. Self-reschedules perpetually.
💰
houseBalance() — returns current vault balance.
deposit() payable onlyOwner — adds funds to vault, resets vaultFloor to 50% of new total.
withdraw(amount) onlyOwner — owner withdraws from vault.
setPaused(bool) onlyOwner — emergency pause/unpause.
startAutoManage() — owner call once after deploy to activate the Scheduler vault manager.
Security Features
🎲drand verifiable randomness — fetched inside Ritual TEE, attested, injected via fulfilled replay. Unpredictable and unmanipulable by any party.
🔒Reentrancy guard — prevents recursive call attacks.
📏Max bet = 5% of vault (enforced on-chain in every flip() call) — protects vault even during win streaks.
🪙Min bet 0.0005 RITUAL — blocks dust spam.
🛡️Vault floor — auto-pauses if vault falls below 50% of its initial value. Auto-unpauses when vault recovers.
🔑Session wallet anti-phishing — signing message is domain-bound (ritual-flip.vercel.app). A phishing site with a different domain cannot replay the same signature to derive your game wallet.
📦Unlimited concurrent players — each game wallet is a separate EOA. No shared queue, no race conditions, scales linearly.
📊Emits FlipResult and FlipRefunded — fully auditable on-chain.
⚠️
Testnet only. RITUAL tokens have no monetary value. Contract has not been formally audited. Do not use this pattern on mainnet without a full security review.
🌐

RITUAL TESTNET

Network NameRitual Testnet
Chain ID1979
RPC URLhttps://rpc.ritualfoundation.org
CurrencyRITUAL (native, 18 decimals)
Explorerexplorer.ritualfoundation.org
Faucetfaucet.ritualfoundation.org
Block Time~350ms
RitualWallet0x532F0dF0896F353d8C3DD8cc134e8129DA2a3948
Auto add network: Click the 🌐 button in the top bar — the app adds Ritual Testnet to your wallet in one click.

Manual: Add a custom network using the details above.

FAQ

Is this real money?
No. RITUAL is a testnet token with zero monetary value. This game exists to showcase on-chain gaming and session wallet UX on the Ritual network.
What is a Game Wallet and why do I need one?
A game wallet is a regular Ethereum EOA derived from your MetaMask signature. Instead of MetaMask popping up on every flip, your game wallet signs transactions silently in the background.

You fund it once, then flip as many times as you want with zero interruptions. You can withdraw your remaining balance back to MetaMask at any time.
Is the game wallet safe? Can someone steal my funds?
The game wallet private key is derived in your browser from your MetaMask signature and is never stored or sent anywhere. It only exists in memory for the duration of your session.

The signing message includes the domain ritual-flip.vercel.app — a phishing site with a different URL cannot reproduce the same game wallet from the same signature. Keep game wallet funds small (just enough to play), as they are hot wallet funds by nature.
Why does it take 10–30 seconds per flip?
Ritual's 0x0801 precompile makes a live HTTP request to drand.cloudflare.com inside a TEE to fetch verifiable randomness. This fetch takes a few seconds, then Ritual re-executes your transaction with the result injected. The delay is the price of true verifiable randomness — not a bug.
How is the coin flip result decided?
Via drand — a public distributed randomness beacon. Your flip() tx triggers Ritual's 0x0801 HTTP precompile to fetch the latest drand round inside a TEE. Result = keccak256(drand_body, player_address, block_number) % 2. Neither the house, the player, nor validators can predict or influence it. Every flip is auditable on the explorer.
What is the house fee and where does it go?
2% of every bet. It stays in the contract vault regardless of win or lose. On a win of 0.01 RITUAL you receive 0.0196. The vault grows over time from fees, sustaining future payouts.
Why can't I bet more than a small amount?
Max bet is hard-capped at 5% of the vault in every flip() call on-chain. This protects the vault during win streaks. The Scheduler's autoManage() also updates the displayed maxBet every ~12 minutes. As the vault grows, the max bet grows with it.
What is RitualWallet credit and why does it get deposited?
Each flip costs ~0.000044 RITUAL in precompile fees, charged to the game wallet's RitualWallet credit (a separate system contract). The app auto-deposits 0.005 RITUAL credit when your balance drops below 0.002 RITUAL. You don't need to manage this manually — it happens invisibly before each flip.

RitualWallet credit is locked for a very long time after deposit (by design, to prevent spam), but it drains naturally through gameplay at ~228 flips per 0.01 RITUAL deposited.
What is Martingale mode?
A betting strategy: double your bet after every loss, reset to base bet after a win. The idea is to recover losses with one win — but it carries risk of hitting the max bet cap. Use responsibly.
Will my stats disappear when I reload?
No. Stats are saved to localStorage and survive reloads. Reset with the 🗑 button in the Stats panel. Your game wallet is also re-derived automatically when you reconnect and sign again — same wallet every time.
The game is paused. Why?
The autonomous vault manager pauses the game if the vault drops below 50% of its initial value, to protect solvency. It auto-unpauses when the vault recovers. If you see a persistent pause, contact @nheofour on Telegram.
Where do I get RITUAL tokens?
From the official Ritual Faucet: faucet.ritualfoundation.org. Free — connect your wallet and claim.
I found a bug. How do I report it?
DM on X: @nheoweb3
Telegram: @nheofour