Giter Club home page Giter Club logo

rps3's Introduction

RPS3

A simple rock paper scissors game decentralized with Chainlink VRF.

Built as a learning project in the Crypto Academy of Vacuumlabs.

Project Structure

foundry
  └─ backend eth smart contracts
frontend
  └─ next.js frontend

Developing locally (local blockchain)

  1. Copy example env for both the /foundry and /frontend directories.
$ cp ./foundry/.env.example ./foundry/.env
$ cp ./frontend/.env.example ./frontend/.env
  1. (in a separate terminal) Start NextJS development.
$ cd frontend
$ yarn install
$ yarn dev
  1. (in a separate terminal) run a local blockchain using anvil. Take note of a private key add it to the /foundry .env as LOCAL_DEV_ANVIL_PRIVATE_KEY and import it using Metamask or a wallet of your choice.
$ anvil
  1. Run the LocalDeployment script as seen on the /foundry README. This will also output some addresses that needs to be placed in their respective .env:

/foundry env vars:

  • LOCAL_DEV_VRF_COORDINATOR_V2_MOCK_ADDRESS
  • LOCAL_DEV_VRF_V2_WRAPPER_ADDRESS
  • LOCAL_DEV_ROCK_PAPER_SCISSORS_ADDRESS

/frontend env vars:

  • NEXT_PUBLIC_NETWORK - set to hardhat
  • NEXT_PUBLIC_LOCAL_ROCK_PAPER_SCISSORS_ADDRESS
$ cd foundry
$ forge script script/LocalDeployment.s.sol:LocalDeploymentScript --rpc-url "http://127.0.0.1:8545" --broadcast -vvvv
  1. Fund the address you'll use to play the game by adding your wallet of choice to the /foundry .env as LOCAL_DEV_ADDRESS. Once added you can run this command:
$ forge script script/SendEtherLocal.s.sol:SendEtherLocalScript --rpc-url "http://127.0.0.1:8545" --broadcast -vvvv
  1. Open http://localhost:3000 to view the frontend UI, and connect your wallet with the account you just funded.

  2. Select a choice and play the game. Be sure to change the Gas limit in your wallet to 500000 since estimations aren't so accurate for local developoment.

  3. Once playGame transaction is confirmed and lastRequestId is updated, run the FulfillRandomWords script as seen on the /foundry README. Be sure to update the LOCAL_DEV_REQUEST_ID to the lastRequestId value.

$ cd foundry
$ forge script script/FullfillRandomWords.s.sol:FullfillRandomWordsScript --rpc-url "http://127.0.0.1:8545" --broadcast -vvvv --skip-simulation --gas-estimate-multiplier 500
  1. If you Won or Draw, you'll be able to withdraw your balance by clicking the Withdraw button.

rps3's People

Contributors

icedevera avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.