Skip to content

0xSenzel/chainlink-graph-randomwinner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Indexing Chainlink VRF V2 Lottery Game using The Graph's Indexer

This repo contains coursework project from LearnWeb3 completed by 0xsenzel for LearnWeb3DAO-Junior lesson.

Project Info

Randomness source from Chainlink VRF V2 to pick random winner for lottery game. Log the winners using The Graph Indexing.

Project Demo

demo1

Fig.1 - Home Page


demo2

Fig.2 - Connected with wallet


demo3

Fig.3 - Connect with Owner's Wallet to Start Game


demo4

Fig.4 - Home Page View Once Game Started


Note

Under the situation were you were unable to join, adjust your "Gas Limit" ; "Max Priority Fee" ; "Max Fee" accordingly. Here's a guide on how to adjust on Metamask.

metamask1

Project Setup

Hardhat

Head to hardhat-tutorial folder:

Install dependencies

npm install

Compile smart contract

npx hardhat compile

To deploy smart contracts:
Head to hardhat.config.js file, change the value of:

  • ALCHEMY_HTTP_URL with your own Ethereum Network API
  • PRIVATE_KEY with your Ethereum wallet's private key
  • POLYGONSCAN_API_KEY with your Etherscan's API Key

Then run the following command.

npx hardhat run scripts/deploy.js --network goerli
npx hardhat verify --network mumbai YOUR_SMARTCONTRACT_ADDRESS "CONSTRUCTOR ARG1" "CONSTRUCTOR ARG2"

Subgraph

Head to graph folder:

npm install

Create an account and setup your Subgraph Indexing. Here are some of the command you can use to setup locally:

yarn global add @graphprotocol/graph-cli
graph init --contract-name RandomWinnerGame --product hosted-service GITHUB_USERNAME/Learnweb3  --from-contract YOUR_RANDOM_WINNER_GAME_CONTRACT_ADDRESS  --abi ./abi.json --network mumbai graph
graph auth
yarn codegen
yarn deploy

React & Next Js

Head to my-app folder:

npm install

Replace the variable inside this file:

  • RANDOM_GAME_NFT_CONTRACT_ADDRESS with your deployed smart contract address.

Replace SUBGRAPH_URL located in this file with your own link at The Graph Dashboard.

To run the app locally:

npm run dev

Releases

No releases published

Packages

 
 
 

Contributors