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
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
This section contains frameworks/libraries used to bootstrap Bingo Game, it includes the smart contract and api.
There are four parts of the files: smart contract files,nodeJs Interface files,Nodejs monitor files,Django REST API files.
-
npm
npm install npm@latest -g
-
python
python version >= 3.7.9
Download from here
-
Clone the repo
git clone https://github.com/Astr0-G/Decentralized-Bingo-Game.git
-
Install node_modules
npm install
or
yarn
-
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='' ```
-
smart contract test
yarn hardhat test
-
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
-
run interface scripts
yarn hardhat getplayers yarn hardhat getplayergameboard yarn hardhat getroundbingoresult yarn hardhat getbingobasicdetails yarn hardhat checkwinner
-
run monitor scripts(monitor sctips is running, feel free to test on goerli testnet)
yarn hardhat monitor
-
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
test case 1
one player achieved the bingo in the earliest round and got their the pot of entry fee: Bingo Token
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
test case 3
no players achieved the bingo
return bet is setting to false on this case
test summary
nodejs monitor with keeper log
keeper call drawWinner function 6 mins after the game round created
Winner wins the pot of entry fees, transferred on win
Call interface test
gas report
`drawWinner` function max gas used is the worst case that there is no winners drawed
slither report
you can use yarn slither to do the test, make sure you have slither installed
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
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.
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!
- Fork the Project
- Create your Function Branch (
git checkout -b new/Function
) - Commit your Changes (
git commit -m 'Add some Function'
) - Push to the Branch (
git push origin function/Function
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
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!