/2X

2X is a decentralized application (dApp) that allows users to wager ether in a 1v1 winner-take-all gamble

Primary LanguageJavaScript

MakeWagerDemo ChallengeWagerDemo

2X is a decentralized application (dApp) that allows users to wager ether in a 1v1 winner-take-all gamble. Verified randomness provided via Chainlink VRF and professional security analysis provided via Consensys MythX. Currently only available on Kovan network.

Motivation

Create a lean, user-friendly application that lets users safely wager varying amounts of ether by relying on randomness provided via Chainlink VRF and the proven security Ethereum provides as a platform

  1. Create, deploy, and test Ethereum smart contracts to local, test, and mainnet
  2. Make use of Oracles to fetch off-chain data
  3. Seamlessly connect smart contracts to front-ends built in React

Technology

Getting Started

  1. Clone this repository
git clone https://github.com/JaredBorders/2X 
  1. Install the dependencies
yarn
  1. Create a .env file in the root directory of your project. Add these environment-specific variables on new lines in the form of NAME=VALUE:
  • PRIVATE_KEY={YOUR_KEY_FROM_METAMASK}
  • INFURA_KOVAN_NETWORK={SEE_HERE}
  1. Deploy the contract (WagerFactory) to the Kovan network.
npx hardhat run scripts/deploy.js --network kovan
  1. Once the script finishes deploying the WagerFactory, it will log the address of where the contract was deployed to. Update src/pages/Splash.js with this value. (see wagerFactoryAddress)

  2. Add LINK token to the RandomNumberConsumer contract. (The public state variable stored in the WagerFactory (randomNumberConsumerAddress) records the address of the RandomNumberConsumer contract)

  3. Run the app

yarn start
  1. Any changes made to any of the contracts will require you to recompile them. To recompile
npx hardhat compile
  1. Don't forget to update src/pages/Splash.js with the current address if you redeploy your WagerFactory!

Adding LINK to the RandomNumberConsumer

  1. Copy the WagerFactory address logged after running the deploy script
npx hardhat run scripts/deploy.js --network kovan
npx hardhat console --network kovan 
const Factory = await ethers.getContractFactory("WagerFactory")
const factory = await Factory.attach("ADDRESS_LOGGED_FROM_DEPLOY_SCRIPT")
await factory.randomNumberConsumerAddress()
  1. After getting LINK from a faucet, send it to the address factory.randomNumberConsumerAddress() returns

TODO

  • After wager has expired, automatically send eth back to wagerer. (May be problematic given that it costs gas to both create & remove wager)
  • Further contract testing is always welcome

How to Contribute?

Read this guide first, check TODO list, and don't hesitate to reach out!