A decentralized, provably fair dice betting game built on the Ethereum blockchain. Players can deposit ETH, place bets on dice rolls, and withdraw their winnings securely through a smart contract.
- 🎯 Provably Fair Gaming: Transparent and verifiable randomness using blockchain technology
- 🔒 Secure Smart Contract: Built with reentrancy protection and proper security measures
- 💼 Wallet Integration: Seamless MetaMask integration for easy deposits and withdrawals
- 📊 Real-time Balance Tracking: Monitor your balance and transaction history in real-time
- 🎨 Modern UI: Beautiful, responsive interface built with React and Tailwind CSS
- ⚡ Fast Transactions: Optimized gas usage for efficient blockchain interactions
- Connect Your Wallet: Click "Connect Wallet" and approve the MetaMask connection
- Deposit ETH: Add ETH to your game balance using the deposit function
- Place Your Bet: Enter your bet amount (minimum 0.01 ETH)
- Roll the Dice: Click "Roll Dice" and wait for the result
- Win or Lose:
- Roll 4, 5, or 6: Win 2x your bet! 🎉
- Roll 1, 2, or 3: Lose your bet
- Withdraw: Withdraw your winnings anytime
BetProvably---Web3-Dice-Betting-Game/
├── Dice.sol # Smart contract source code
├── artifacts/ # Compiled contract artifacts
├── src/
│ ├── App.jsx # Main application component
│ ├── Components/
│ │ └── Dice.jsx # Dice component
│ ├── API/
│ │ └── gameAPI.js # API utilities
│ ├── App.css # Application styles
│ └── main.jsx # Application entry point
├── public/ # Static assets
├── package.json # Dependencies
└── vite.config.js # Vite configuration
- Node.js (v16 or higher)
- npm or yarn
- MetaMask browser extension
- Ethereum wallet with test ETH (for testnet) or mainnet ETH
-
Clone the repository
git clone https://github.com/yourusername/BetProvably---Web3-Dice-Betting-Game.git cd BetProvably---Web3-Dice-Betting-Game -
Install dependencies
npm install
-
Configure environment variables (optional) Create a
.envfile in the root directory:VITE_CONTRACT_ADDRESS=0xYourContractAddress
If not set, the app will use the default contract address.
-
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173(or the port shown in your terminal)
npm run buildThe production build will be in the dist/ directory.
The contract address is configurable via environment variables. Default: 0x2aF3733Be093331b70b4Ff07141C4F3FD3960b55
deposit(): Deposit ETH into your game balancewithdraw(uint256 amount): Withdraw ETH from your game balancerollDice(uint256 betAmount): Place a bet and roll the dicegetBalance(address player): Get the balance of a specific playerbalances(address): Public mapping to check any player's balance
-
DiceRolled: Emitted when a dice roll occursplayer: Address of the playerroll: The dice result (1-6)win: Whether the player wonbetAmount: Amount betpayout: Amount won (0 if lost)
-
Deposit: Emitted when a deposit is made -
Withdraw: Emitted when a withdrawal is made
- ✅ Reentrancy protection using
nonReentrantmodifier - ✅ Input validation for all functions
- ✅ Safe ETH transfers using
call()instead oftransfer() - ✅ Enhanced randomness using multiple block parameters
- React 19.0.0 - UI framework
- Vite 6.2.0 - Build tool and dev server
- Tailwind CSS 4.0.9 - Styling
- Ethers.js 5.7.2 - Ethereum interaction library
- Solidity ^0.8.0 - Smart contract language
- Hardhat - Development environment (for compilation)
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLint
If you need to recompile the contract:
# Install Hardhat (if not already installed)
npm install --save-dev hardhat
# Compile the contract
npx hardhat compileBefore deploying to mainnet, always test on a testnet:
- Deploy to Sepolia/Goerli testnet
- Get test ETH from a faucet
- Test all functions thoroughly
- Verify contract on Etherscan
- This is a gambling application. Please gamble responsibly and only with funds you can afford to lose.
- Smart contract is immutable once deployed. Always audit contracts before mainnet deployment.
- Gas fees apply to all transactions on Ethereum.
- Test thoroughly on testnets before using real funds.
This project is licensed under the MIT License.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
For questions, support, or collaboration opportunities:
Telegram: t.me/moooncity
Disclaimer: This software is provided "as is" without warranty. Use at your own risk. The developers are not responsible for any financial losses incurred while using this application.