Skip to content

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

License

Notifications You must be signed in to change notification settings

Pedrojok01/CoinFlip_2.0

Repository files navigation

CoinFlip - Double up your ETH!

Stargazers Issues MIT License LinkedIn Netlify Status

Preview

Table of Contents

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
  • solidity
  • chainlink
  • hardhat
  • ethers.js

Getting Started

Prerequisites

Make sure you have the following ready:

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 .

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 the COORDINATOR and KEY_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

Coverage

To check the coverage of the tests, run the following command:

yarn cover

And see the results printed in the terminal:

Preview

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_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!!!)

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! ⭐️

(back to top)