- 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;
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/
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
Then create a new repo, open your favorite code editor, and clone the repo with the following cmd:
git clone https://github.com/Pedrojok01/CoinFlip_2.0 .
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
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 theCOORDINATOR
andKEY_HASH
values. 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.js
and that you have defined the required variables in the.env
file. - Edit the script in
blockchain/package.json
to deploy the contract on the network of your choice. - Finally, run the command below to deploy to the network of your choice.
yarn deploy
To check the coverage of the tests, run the following command:
yarn cover
And see the results printed in the terminal:
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.
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_ADDRESS
in/src/constants.js
to your deployed contracts address; - Copy the new abi file into the
src/abis
folder 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.secret
and paste your mnemonic seed phrase inside; (Make sure you add this file in your.gitignore
!!!)
You are now set to start your local server. Make sure you're still in COINFLIP 2.0
and type:
yarn start