A simple rock paper scissors game decentralized with Chainlink VRF.
Built as a learning project in the Crypto Academy of Vacuumlabs.
foundry
└─ backend eth smart contracts
frontend
└─ next.js frontend
- Copy example env for both the /foundry and /frontend directories.
$ cp ./foundry/.env.example ./foundry/.env
$ cp ./frontend/.env.example ./frontend/.env
- (in a separate terminal) Start NextJS development.
$ cd frontend
$ yarn install
$ yarn dev
- (in a separate terminal) run a local blockchain using anvil. Take note of a private key add it to the /foundry
.env
asLOCAL_DEV_ANVIL_PRIVATE_KEY
and import it using Metamask or a wallet of your choice.
$ anvil
- 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 tohardhat
NEXT_PUBLIC_LOCAL_ROCK_PAPER_SCISSORS_ADDRESS
$ cd foundry
$ forge script script/LocalDeployment.s.sol:LocalDeploymentScript --rpc-url "https://127.0.0.1:8545" --broadcast -vvvv
- Fund the address you'll use to play the game by adding your wallet of choice to the /foundry
.env
asLOCAL_DEV_ADDRESS
. Once added you can run this command:
$ forge script script/SendEtherLocal.s.sol:SendEtherLocalScript --rpc-url "https://127.0.0.1:8545" --broadcast -vvvv
-
Open https://localhost:3000 to view the frontend UI, and connect your wallet with the account you just funded.
-
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. -
Once
playGame
transaction is confirmed andlastRequestId
is updated, run theFulfillRandomWords
script as seen on the /foundry README. Be sure to update theLOCAL_DEV_REQUEST_ID
to thelastRequestId
value.
$ cd foundry
$ forge script script/FullfillRandomWords.s.sol:FullfillRandomWordsScript --rpc-url "https://127.0.0.1:8545" --broadcast -vvvv --skip-simulation --gas-estimate-multiplier 500
- If you Won or Draw, you'll be able to withdraw your balance by clicking the Withdraw button.