Skip to content

astr0-g/Decentralized-Bingo-Game

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Dencentralized Bingo Game

Dencentralized Bingo Game basis for EVM chain
Explore the docs »

Report Bug


dencentralized bingo game on Goerli Testnet Network
Bingo game smart contract
Bingo Token smart contract
Explore the deployment data »

Table of Contents
  1. About The Project
  2. Getting Started
  3. Test Summary and Gas Report
  4. Interface-abi
  5. Public-API
  6. Contributing
  7. License
  8. Contact

About The Project

Dencentralized Bingo Game

Bingo is a luck-based game in which players match a randomized board of numbers with random numbers drawn by a host. The first player to achieve a line of numbers on their board and claim Bingo wins.

BasicBingoGame.sol: this is the game version for test cases, test for optimize gas and logic.

  • Draw winners function and claim prize function are sticked together as "drawWinnerOrClaimPrize"(there is no need for automation keepers to involve for this contract)

  • Support 4 players in a game as default(could change on game needs)

  • Support unlimited multiple concurrent games

  • Each player pays an ERC20 entry fee: Bingo Token, transferred on join

  • Winner wins the pot of entry fees(player needs to claim their prize or bet by calling "drawWinnerOrClaimPrize" function)

  • Games have a minimum join duration before start

  • Games have a minimum turn duration between draws

  • Admin can update the entry fee: Bingo Token, join duration, turn duration, whether return bet and max plyer in one game

BingoGame.sol: this is the game version for real world cases, which is the one deployed on Goerli testnet.

  • Draw winners function "drawWinner" will be called by automation keeper

  • Support 4 players in a game as default(could change on game needs)

  • Support unlimited multiple concurrent games

  • Each player pays an ERC20 entry fee: Bingo Token, transferred on join

  • Winner wins the pot of entry fees, transferred on win(player needs to claim their bet back by calling "claimPrize" function)

  • Games have a minimum join duration before start

  • Games have a minimum turn duration between draws

  • Admin can update the entry fee: Bingo Token, join duration, turn duration, whether return bet and max plyer in one game

BingoToken.sol: Normal ERC20 standard token

more infos:

  • ReturnBet sets to true as default means returns bet token amount when there is no winner for a game
  • Random numbers is generated with blockhash(block.number - 1)
  • Duplicate numbers may be drawn, but have no effect on the game
  • Boards may have duplicate numbers that can be marked by one drawn number
  • Each game number is between 0 and 64
  • Players are online to claim a game board and prize with transaction

(back to top)

Built With

This section contains frameworks/libraries used to bootstrap Bingo Game, it includes the smart contract and api.

hardhat
node.js
django

(back to top)

Getting Started

There are four parts of the files: smart contract files,nodeJs Interface files,Nodejs monitor files,Django REST API files.

Prerequisites

  • npm

    npm install npm@latest -g
  • python
    python version >= 3.7.9
    Download from here

Installation

you can skip 6-8 if you are only testing smart contracts
  1. Clone the repo

    git clone https://github.com/Astr0-G/Decentralized-Bingo-Game.git
  2. Install node_modules

    npm install

    or

    yarn
  3. create a .env file

    create a .env file and put

    ```
    RINKEBY_PRIVATE_KEY=0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e
    MUMBAI_PRIVATE_KEY=0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e
    RINKEBY_RPC_URL=https://eth-rinkeby.alchemyapi.io/v2/12345
    PASSWORD=
    GOERLI_RPC_URL=https://goerli.infura.io/v3/12345
    ETHERSCAN_API_KEY=
    COINMARKET_KEY=
    MUMBAI_RPC_URL=https://polygon-mumbai.infura.io/v3/12345
    ARB_RPC_URL=https://arbitrum-mainnet.infura.io/v3/12345
    rpc=''
    ```
    
  4. smart contract test

    yarn hardhat test
    
    
  5. smart contract deploy

    hardhat local network deploy

    yarn hardhat deploy
    

    deploy BingoToken.sol and Bingo.sol to goerli

    yarn hardhat deploy --network goerli --tags bingo
    
  6. run interface scripts

    yarn hardhat getplayers
    yarn hardhat getplayergameboard
    yarn hardhat getroundbingoresult
    yarn hardhat getbingobasicdetails
    yarn hardhat checkwinner
    
    
  7. run monitor scripts(monitor sctips is running, feel free to test on goerli testnet)

    yarn hardhat monitor
    
    
  8. Django rest api

    cd public-api
    
    

    create a .env file and put

    providerurl=https://eth-goerli........
    

    install requirements.txt

    python manage.py migrate
    
    
    python manage.py runserver
    
    

    you may choose Postman to test REST api

(back to top)

Test-Summary-and-Gas-Report

Test-Summary

test case 1

one player achieved the bingo in the earliest round and got their the pot of entry fee: Bingo Token

bingo


test case 2

two or more players achieved the bingo in the same earliest round and split the pot of entry fee: Bingo Token

changed generated number range from 64 to 10 just for this test

bingo


test case 3

no players achieved the bingo

return bet is setting to false on this case

bingo


test summary

bingo


nodejs monitor with keeper log

bingo


keeper call drawWinner function 6 mins after the game round created

bingo


Winner wins the pot of entry fees, transferred on win

bingo


Call interface test

bingo


Gas-Report

gas report

`drawWinner` function max gas used is the worst case that there is no winners drawed

bingo


slither report

you can use yarn slither to do the test, make sure you have slither installed

bingo


(back to top)

Interface-abi

interface file of BingoGame.sol is abi.json

NodeJs scripts:

checkWinner : for frontend to check if the player is winner

getBingoBasicDetails : for frontend to get bingo basic details

getPlayerGameBoard : for frontend to render player game number board

getPlayers : for frontend to get players address in a round of game

getRoundBingoResult : for frontend to get specific round of Bingo result

(back to top)

Public-API

API are constructed based on Django, check the files here.

API endpoints:

get bingo game details https://www.decentralizedbingogame.live/api/getbingobasicdetails/

get player game board https://www.decentralizedbingogame.live/api/getplayergameboard/<playeraddress>/<gameround>/

get player from gameround https://www.decentralizedbingogame.live/api/getplayer/<gameround>/

get round bingo result and winning numbers from game round https://www.decentralizedbingogame.live/api/getroundbingoresult/<gameround>/

check if player is winner in the game round https://www.decentralizedbingogame.live/api/checkwinner/<playeraddress>/<gameround>/

get all round detils
https://www.decentralizedbingogame.live/api/get10rounddetils/
*Please wait couple minutes after clicking "get all round detils", it really takes some time.
*For get all round details, will soon make it to 10 rounds of data showing, because there is no database Django using right now, will need to set up database later on to save data into bingo game database everytime when emit an event which is also for best performance for frontend.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Function Branch (git checkout -b new/Function)
  3. Commit your Changes (git commit -m 'Add some Function')
  4. Push to the Branch (git push origin function/Function)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

astro - @lil_astr_0 - [email protected]

Project Link: github

please dm on twitter if you need Goerli Testnet Native Token to test Bingo Game, I am happy to help!

(back to top)


About

decentralized bingo game solidity smart contract

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published