EVM compatible Dapp built with React/Hardhat/Chainlink-VRF2 => Flip a coin to double your ETH!

Table of Contents
- Prerequisites - Smart-Contracts Deployment - Install the dependencies - Deployement - Coverage - Static Analyzer - Config \& Client - ⭐️ ... and don't forget to leave a star if you like it! ⭐️Updates
- 2024/06 - Move from Truffle to Hardhat & Switch to Spolia network & Update to Chainlink VRF 2.5 & compiler to 0.8.20 & Clean contracts/app;
- 2022/07 - Switch to Chainlink VRF v2 & Update solidity compiler version to 0.8.7;
- 2022/12 - Switch to Goerli network v2 & upgrade all deps & Update solc to 0.8.16;
Description
Decentralized application (Dapp), EVM compatible, built as a part of the programming course: Ethereum201 on academy.moralis.com.
The app is a simple coin flip game where you can double up your ETH or lose your bet. The game is based on a smart contract that uses Chainlink VRF to generate a random number.
Smart contracts deployed on Sepolia testnet: 0x097d039Bb7353B0bcD3d585B5a71e8B575F2f3f7
Try it yourself: coinflip-double-up-your-eth.netlify.app/
Built With
- [![React][react.js]][react-url]
- [![solidity]][solidity-url]
- [![chainlink]][chainlink-url]
- [![hardhat]][hardhat-url]
- [![ethers.js]][ethers-url]
Getting Started
Prerequisites
Make sure you have the following ready:
- node.js installed (developed on LTS v20.12.0)
- yarn installed
- hardhat installed
- MetaMask installed in your browser
git clone https://github.com/Pedrojok01/CoinFlip_2.0 .
Smart-Contracts Deployment
Install the dependencies
In your terminal, make sure you are in the COINFLIP_2.0 repo, then move to the blockchain folder :
cd blockchain
Then run the following command to install the dependencies:
yarn install
Deployement
To deploy your smart-contracts:
- Subscribe to Chainlink VRF v2.5 on the Chainlink VRF Sepolia dashboard. You can get some test LINK there: LINK Faucet.
- Add your subscription id to the deployment script in
blockchain/scripts/deploy.js. To deploy on different chains, you will also have to adjust theCOORDINATORandKEYHASHvalues. You can refer to the Chainlink docs to get the data for the desired network (if supported). - Also, make sure that the network is configured in
hardhat.config.jsand that you have defined the required variables in the.envfile. - Edit the script in
blockchain/package.jsonto deploy the contract on the network of your choice. - Finally, run the command below to deploy to the network of your choice.
yarn deploy
Coverage
To check the coverage of the tests, run the following command:
yarn cover
And see the results printed in the terminal:

Static Analyzer
For basic security checks, you can run both Slither and Aderyn (refer to their doc to install them) with the following commands:
yarn slither
yarn aderyn
Aderyn will print a nice report file called report.md at the root of the project.
Config & Client
Before each deployment, make sure to:
- Replace the contract address in
src/data/constants.js - Replace the abi file in
src/data/coinFlipAbi.js - Make sure to fund the contract with some ETH ( Faucet for the Sepolia network )
- Change the
COINFLIP_ADDRESSin/src/constants.jsto your deployed contracts address; - Copy the new abi file into the
src/abisfolder if you've made any changes to the contracts; - Enable/disable, and update the suitable networks in
truffle-config.js; - In the
blockchain/repo, create a file called.secretand paste your mnemonic seed phrase inside; (Make sure you add this file in your.gitignore!!!)
Acknowledgments
Use
You are now set to start your local server. Make sure you're still in COINFLIP 2.0 and type: yarn start
# Enjoy!!!
⭐️ ... and don't forget to leave a star if you like it! ⭐️
[react.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB [react-url]: https://reactjs.org/ [chainlink]: https://img.shields.io/badge/chainlink-375BD2?style=for-the-badge&logo=chainlink&logoColor=61DAFB [chainlink-url]: https://chain.link/ [solidity]: https://img.shields.io/badge/Solidity-35495E?style=for-the-badge&logo=solidity&logoColor=4FC08D [solidity-url]: https://soliditylang.org/ [hardhat]: https://img.shields.io/badge/Hardhat-ffc517?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADoAAAA1CAYAAAAQ7fj9AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAWUSURBVGhD7ZlrTFtlGIBPWwpt7VoRERghRCM44x+zwRKNmUbUwebmLZvXKWjihSnxD7DE/VgCS3Qui9nUqD82My8bsokzjggbl82BBgcMGDCGQwKMoQiFcR8br9/7wam9vOfSnm5xXX88Sdtze5++3/d+7zlHiF2cCDcCIdFgIyQabIREA8VTT8bA5k23wIdbb+bUlJs44vec7ChIS4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tVZbEay6o+wPR5qrjKQLIilKiXniS0YRrMIpS2/iFZfa7g+4vI2weoGcb5BuHCRFh06xPlIBLEjUxeX4sciq6V7UE+yMHGwaIX2srlAuiLRoI5NBmBAOC2zesQPBE+PzIWyoA/XETws4dMUR1nfSR9HMDdH8BLzr+R/IqOHSABu6LQbJ1xteoviYgjrR9QT1tN9LlDoQnwc1HguH5uNGqDhggqrvTdBRp23984fG6nA4Wmzi4GepGPCViKcXKdrxuxFO/BQBx0si4Ey1watRwImP62jldxGaXj+oBYXqDxv/qxse4LbKoggoKzJDX6tBnWh5kYmvj24slG/e9nkIt1cYeLapAANB5UETKSfHJ+8vcnNCvESTkxMgOysKjuwzORdifqfiIu0mvJDdhlIjVLGgcEjhv0oFrQbMHh+i7A9vO2ogRSi6a/Swe7sVXnwm2s1HxEvUkycyYiA/JxJ2Ftq4fE+d3lt4QZaXeVxjiUACSUtZGPy81wQFuXZ48+UoeOgB5RfJiqJSLFsaD2vTYziF+XYozLNDAaP4MwsPQgoxSDk+2mLjEkhudiSsXcmuw0hKusbvXq5HQqLBRkg02AiJBhsh0WAjJBps3CCiifAv+kBDzN+k+08AAAAASUVORK5CYII= [hardhat-url]: https://hardhat.org/ [ethers.js]: https://img.shields.io/badge/Ethers.js-2535a0?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADcAAAAwCAYAAAC13uL+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAALVSURBVGhD7ZjPSxdBGIf7Z7p1ky51CS928qQnu5SH9BIeAiFJEAwPVgfx5EkIBCEIgkAIBEEQBOlP2ny+MDDfl8/uvjM7U23s4SHNd2fez7y/ZvfBw8enzf/KJG6sTOLGyiSuBE+enzfPlr/OUH+vQVVxC4tnzebby+bw+K45Ovk1x9a7q+pCq4lbe30hRVkQ+ejpF7nGUKqII1pKSBvvD26qCCwubv3NTymgj+29a7neEIqKo4as0x8+3zbLa99n9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