Skip to content

quyen2971997/solidity-simple-roll-the-dice-game

Repository files navigation

Even Odd Game — The Simple Gambling Smart Contract (Part I)

Solidity logo

The aim of this project is to provide a simple example of Smart Contract application.

Include

  • This Project is written in Solidity. Find out more about Solidity on Solidity Docs v0.8.15.
  • We use Truffle to test and deploy solidity Smart Contract to BSC Testnet. See tutorial.

Simple Workflow

  • Someone bet on Even or Odd
  • Roll the dice then give result & pay winners
  • Repeat...

Smart Contract Main Functions

  • deposit() : Deposit some fund to Smart Contract. The Jackpot shouldn't be empty right? :)
  • putInEven() : Bet on Even. You will send 0.01 test BNB to contract to play
  • putInOdd() : Bet on Odd. You will send 0.01 test BNB to contract to play
  • endBet() : Roll the dice then pay the winners (DOUBLE amount of their bets)
  • Others... See the contract

Note

  • Please note that this contract is not for gamling purpose (Study purpose only).
  • The problem is in the rollTheDice() function.
  • The Pseudorandom number generator from this function is NOT safe for gambling.
  • Chainlink VRF is the best solution for now. Check out

Deploy on BSC Testnet

We made a truffle-project with mostly everything setup. 0. Clone this Project

  1. Put in your mnemonic phrase into a file named .secret
  2. Your above wallet must have some BNB to trigger the smart contract deployment. Get some testnet BNB Here
  3. Install @truffle/hdwallet-provider via:
npm install @truffle/hdwallet-provider
  1. Run command and wait for magic:
truffle migrate --network bscTestnet  
  1. Get Contract address then move to Web3.js to interact with it.

Example

This is the deployed smart contract from BSC Testnet. Feel free to send it some funds. It's free anyway :P 0x498B0384D00bB9ba49f4eD2C88bc257B110670bc

Interact with Smart Contract

Even Odd Game — Interact with Smart Contract (Part II)

About

Apply a simple game which let users bet "Even" or "Odd" side then roll the dice to determine the winners

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published