Skip to content
Projects

About

A provably fair dice game on Stellar: a Soroban commit-reveal contract with an Express API and a React front end.

Web & App Development

How these counts are measured

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

TrueRoll

A provably fair dice game on Stellar. Players bet on a number from 1 to 6; the result comes from combining a player secret and a house secret with a commit-reveal scheme, so neither side can change the roll after the bet is placed.

Part What works
contract/ Escrow, house commit, both reveals, roll, 5x payout, 24h refund, events, TTL bumps, 13 tests
backend/ Read-only Express API over Soroban RPC: health, house state, a game by id, stats, history
frontend/ Real Freighter connect, place_bet and reveal_player calls, polling, refund button
backend/scripts/house.mjs House bot that rotates its commitment and reveals games waiting on the house

The roll is only decided once the house reveals, so a player cannot see the outcome before committing. The contract is unaudited testnet software; see Security.

How the game works

  1. The house commits: house_commit stores sha256(house_secret) on the contract. Bets are refused while no commitment is stored, which is how the game pauses between rotations.
  2. The player picks a number and a wager, hashes a random 32-byte secret and calls place_bet. The contract checks the guess (1–6) and the minimum bet, then moves the wager into escrow.
  3. The player calls reveal_player with the secret. The contract checks sha256(secret) against the commitment from step 2.
  4. The house calls reveal_house with its secret. The contract checks it against the stored commitment, derives the roll and settles:
    • seed = first_four_bytes(player_secret) XOR first_four_bytes(house_secret)
    • roll = (seed % 6) + 1
    • a correct guess pays bet × 5 from the contract balance; a wrong one pays nothing.
  5. If the house never reveals, the player can call refund after 24 hours and get the wager back.

The house bot derives its secrets from one seed (sha256(HOUSE_SECRET:i)), commits to index i + 1 every run and never reuses a revealed secret.

Stack

Layer Technology
Contract Rust, Soroban SDK 25, built for wasm32v1-none (Rust 1.84+)
Backend Node.js 20, Express 4, @stellar/stellar-sdk 17, Jest + Supertest
Frontend React 18, Vite 5, Tailwind CSS 3, Freighter, @stellar/stellar-sdk 17
CI GitHub Actions: contract format/clippy/tests/wasm build, frontend build, backend tests, gitleaks, house bot, Pages

Layout

contract/    Soroban contract (src/lib.rs, src/test.rs)
backend/     Express API (src/app.js, src/services/contract.js, src/__tests__)
frontend/    Vite app (src/App.jsx, src/lib/contract.js, src/components/WalletButton.jsx)
scripts/     deploy-testnet.mjs
backend/scripts/  house.mjs, the bot that settles games

Quick start

# contract
cd contract
rustup target add wasm32v1-none
cargo test
cargo build --target wasm32v1-none --release

# deploy to testnet (prints the contract id and the house secret)
cd ..
node scripts/deploy-testnet.mjs

# backend
cd backend
cp .env.example .env      # CONTRACT_ID, STELLAR_RPC_URL, PORT
npm install
npm test
npm start                 # http://localhost:3001

# frontend
cd ../frontend
cp .env.example .env      # VITE_CONTRACT_ID, VITE_SOROBAN_RPC_URL, VITE_NETWORK_PASSPHRASE
npm ci
npm run dev               # http://localhost:5173

The live app is at https://stellar-soroban.github.io/trueroll/. The house bot runs every five minutes from GitHub Actions and needs the HOUSE_SECRET repository secret plus the CONTRACT_ID and STELLAR_RPC_URL repository variables.

Troubleshooting

Wallet not detected

  • Symptom: The connect button displays Install Freighter instead of connecting.
  • Cause: The Freighter browser wallet extension is missing or disabled.
  • Fix: Install Freighter, create or unlock an account, and reload the page.

Wrong network

  • Symptom: Signing or submitting a bet fails with a network or transaction error.
  • Cause: Freighter is set to a different Stellar network than VITE_NETWORK_PASSPHRASE (which defaults to Stellar Testnet).
  • Fix: Switch Freighter to Testnet (or set VITE_NETWORK_PASSPHRASE in frontend/.env to match your target network) and retry.

Missing contract id

  • Symptom: The app throws VITE_CONTRACT_ID is not set. Copy .env.example to .env and fill it in. when interacting with the contract.
  • Cause: frontend/.env is missing or VITE_CONTRACT_ID is empty.
  • Fix: Copy frontend/.env.example to frontend/.env, set VITE_CONTRACT_ID to your deployed contract id, and restart npm run dev.

House reveal delayed

  • Symptom: A game stays on Waiting for house reveal after your player reveal succeeds.
  • Cause: The house bot workflow runs on a five-minute GitHub Actions schedule and may not have executed yet.
  • Fix: Wait up to about five minutes for the next scheduled run (or run backend/scripts/house.mjs locally). If the house still has not revealed after 24 hours, you can claim a refund.

Contract interface

Function Arguments Returns
initialize house: Address, token: Address Result<(), DiceError>
house_commit house: Address, commit: BytesN<32> Result<(), DiceError>
place_bet player: Address, bet_amount: i128, player_guess: u32, player_commit: BytesN<32> Result<u64, DiceError>
reveal_player player: Address, game_id: u64, player_secret: BytesN<32> Result<(), DiceError>
reveal_house house: Address, game_id: u64, house_secret: BytesN<32> Result<u32, DiceError>
refund player: Address, game_id: u64 Result<(), DiceError>
get_game game_id: u64 Option<Game>
get_game_count / get_house / get_token - u64 / Address / Address
get_house_commit - Option<BytesN<32>>
payout_multiplier - i128 (5)
max_bet - i128 (1,000 XLM)

Game carries the id, player, bet, guess, both commitments, status, roll, payout and timestamp. Status is one of WaitingForPlayerReveal, WaitingForHouseReveal, Settled or Refunded.

Amounts are in stroops (1 XLM = 10,000,000 stroops). Bets are between 0.1 and 1,000 XLM.

Checks

cd contract && cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings && cargo test
cd frontend && npm ci && npm run lint && npm run format:check && npm test && npm run build
cd backend  && npm ci && npm test

CI runs the same commands plus a wasm release build and a gitleaks scan.

Security

Please report vulnerabilities privately through GitHub's security advisories; see SECURITY.md. This is unaudited testnet software. Do not put real funds behind it. The house bot is a scheduled job, so a game can wait up to about five minutes for the house reveal (see Troubleshooting).

Contributing

Issues are labelled by area and difficulty. CONTRIBUTING.md covers the workflow. New here? Filter for good first issue — comment on an issue to claim it, no permission needed. Everyone who has landed work is listed in CONTRIBUTORS.md.

License

MIT, see LICENSE.

Explore related projects

Loading…