-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4bd70b6
Showing
168 changed files
with
26,355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules | ||
|
||
# dependencies, yarn, etc | ||
# yarn / eslint | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.eslintcache | ||
.vscode/** | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
# yarn lint-staged --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const path = require("path"); | ||
|
||
const buildNextEslintCommand = (filenames) => | ||
`yarn next:lint --fix --file ${filenames | ||
.map((f) => path.relative(path.join("packages", "nextjs"), f)) | ||
.join(" --file ")}`; | ||
|
||
const checkTypesNextCommand = () => "yarn next:check-types"; | ||
|
||
const buildHardhatEslintCommand = (filenames) => | ||
`yarn hardhat:lint-staged --fix ${filenames | ||
.map((f) => path.relative(path.join("packages", "hardhat"), f)) | ||
.join(" ")}`; | ||
|
||
module.exports = { | ||
"packages/nextjs/**/*.{ts,tsx}": [ | ||
buildNextEslintCommand, | ||
checkTypesNextCommand, | ||
], | ||
"packages/hardhat/**/*.{ts,tsx}": [buildHardhatEslintCommand], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/dist/esm/useLocalStorage/useLocalStorage.js b/dist/esm/useLocalStorage/useLocalStorage.js | ||
index b0d584d4df29953551dfcf8febac002f89fa7acd..920ae5c52d28af73e3a892bdb935a7805a0f8224 100644 | ||
--- a/dist/esm/useLocalStorage/useLocalStorage.js | ||
+++ b/dist/esm/useLocalStorage/useLocalStorage.js | ||
@@ -14,7 +14,7 @@ function useLocalStorage(key, initialValue) { | ||
return initialValue; | ||
} | ||
}, [initialValue, key]); | ||
- const [storedValue, setStoredValue] = useState(readValue); | ||
+ const [storedValue, setStoredValue] = useState(initialValue); | ||
const setValue = useEventCallback(value => { | ||
if (typeof window === 'undefined') { | ||
console.warn(`Tried setting localStorage key β${key}β even though environment is not a client`); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
enableColors: true | ||
|
||
nmHoistingLimits: workspaces | ||
|
||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs | ||
spec: "@yarnpkg/plugin-typescript" | ||
|
||
yarnPath: .yarn/releases/yarn-3.2.3.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Welcome to Scaffold-ETH 2 Contributing Guide | ||
|
||
Thank you for investing your time in contributing to Scaffold-ETH 2! | ||
|
||
This guide aims to provide an overview of the contribution workflow to help us make the contribution process effective for everyone involved. | ||
|
||
## About the Project | ||
|
||
Scaffold-ETH 2 is a minimal and forkable repo providing builders with a starter kit to build decentralized applications on Ethereum. | ||
|
||
Read the [README](README.md) to get an overview of the project. | ||
|
||
### Vision | ||
|
||
The goal of Scaffold-ETH 2 is to provide the primary building blocks for a decentralized application. | ||
|
||
The repo can be forked to include integrations and more features, but we want to keep the master branch simple and minimal. | ||
|
||
### Project Status | ||
|
||
The project is under active development. | ||
|
||
You can view the open Issues, follow the development process and contribute to the project. | ||
|
||
## Getting started | ||
|
||
You can contribute to this repo in many ways: | ||
|
||
- Solve open issues | ||
- Report bugs or feature requests | ||
- Improve the documentation | ||
|
||
Contributions are made via Issues and Pull Requests (PRs). A few general guidelines for contributions: | ||
|
||
- Search for existing Issues and PRs before creating your own. | ||
- Contributions should only fix/add the functionality in the issue OR address style issues, not both. | ||
- If you're running into an error, please give context. Explain what you're trying to do and how to reproduce the error. | ||
- Please use the same formatting in the code repository. You can configure your IDE to do it by using the prettier / linting config files included in each package. | ||
- If applicable, please edit the README.md file to reflect the changes. | ||
|
||
### Issues | ||
|
||
Issues should be used to report problems, request a new feature, or discuss potential changes before a PR is created. | ||
|
||
#### Solve an issue | ||
|
||
Scan through our [existing issues](https://github.com/scaffold-eth/scaffold-eth-2/issues) to find one that interests you. | ||
|
||
If a contributor is working on the issue, they will be assigned to the individual. If you find an issue to work on, you are welcome to assign it to yourself and open a PR with a fix for it. | ||
|
||
#### Create a new issue | ||
|
||
If a related issue doesn't exist, you can open a new issue. | ||
|
||
Some tips to follow when you are creating an issue: | ||
|
||
- Provide as much context as possible. Over-communicate to give the most details to the reader. | ||
- Include the steps to reproduce the issue or the reason for adding the feature. | ||
- Screenshots, videos etc., are highly appreciated. | ||
|
||
### Pull Requests | ||
|
||
#### Pull Request Process | ||
|
||
We follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr) | ||
|
||
1. Fork the repo | ||
2. Clone the project | ||
3. Create a new branch with a descriptive name | ||
4. Commit your changes to the new branch | ||
5. Push changes to your fork | ||
6. Open a PR in our repository and tag one of the maintainers to review your PR | ||
|
||
Here are some tips for a high-quality pull request: | ||
|
||
- Create a title for the PR that accurately defines the work done. | ||
- Structure the description neatly to make it easy to consume by the readers. For example, you can include bullet points and screenshots instead of having one large paragraph. | ||
- Add the link to the issue if applicable. | ||
- Have a good commit message that summarises the work done. | ||
|
||
Once you submit your PR: | ||
|
||
- We may ask questions, request additional information or ask for changes to be made before a PR can be merged. Please note that these are to make the PR clear for everyone involved and aims to create a frictionless interaction process. | ||
- As you update your PR and apply changes, mark each conversation resolved. | ||
|
||
Once the PR is approved, we'll "squash-and-merge" to keep the git commit history clean. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 BuidlGuidl | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# π© Challenge 3: π² Dice Game | ||
|
||
 | ||
|
||
> π° Randomness is tricky on a public deterministic blockchain. The block hash is an easy to use, but very weak form of randomness. This challenge will give you an example of a contract using block hash to create random numbers. This randomness is exploitable. Other, stronger forms of randomness include commit/reveal schemes, oracles, or VRF from Chainlink. | ||
> π One day soon, randomness will be built into the Ethereum protocol! | ||
> π¬ Dice Game is a contract that allows users to roll the dice to try and win the prize. If players roll either a 0, 1, 2, 3, 4 or 5 they will win the current prize amount. The initial prize is 10% of the contract's balance, which starts out at .05 Eth. | ||
> 𧀠Every time a player rolls the dice, they are required to send .002 Eth. 40 percent of this value is added to the current prize amount while the other 60 percent stays in the contract to fund future prizes. Once a prize is won, the new prize amount is set to 10% of the total balance of the DiceGame contract. | ||
> 𧨠Your job is to attack the Dice Game contract! You will create a new contract that will predict the randomness ahead of time and only roll the dice when you're guaranteed to be a winner! | ||
> π¬ Meet other builders working on this challenge and get help in the [Challenge 3 telegram](https://t.me/+3StA0aBSArFjNjUx)! | ||
--- | ||
|
||
## Checkpoint 0: π¦ Environment π | ||
|
||
Before you begin, you need to install the following tools: | ||
|
||
- [Node (v18 LTS)](https://nodejs.org/en/download/) | ||
- Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install)) | ||
- [Git](https://git-scm.com/downloads) | ||
|
||
Then download the challenge to your computer and install dependencies by running: | ||
|
||
```sh | ||
git clone https://github.com/scaffold-eth/se-2-challenges.git challenge-3-dice-game | ||
cd challenge-3-dice-game | ||
git checkout challenge-3-dice-game | ||
yarn install | ||
``` | ||
|
||
> in the same terminal, start your local network (a blockchain emulator in your computer): | ||
```sh | ||
yarn chain | ||
``` | ||
|
||
> in a second terminal window, π° deploy your contract (locally): | ||
```sh | ||
cd challenge-3-dice-game | ||
yarn deploy | ||
``` | ||
|
||
> in a third terminal window, start your π± frontend: | ||
```sh | ||
cd challenge-3-dice-game | ||
yarn start | ||
``` | ||
|
||
π± Open http://localhost:3000 to see the app. | ||
|
||
> π©βπ» Rerun `yarn deploy` whenever you want to deploy new contracts to the frontend. If you haven't made any contract changes, you can run `yarn deploy --reset` for a completely fresh deploy. | ||
--- | ||
|
||
## Checkpoint 1: π² Dice Game | ||
|
||
π Inspect the code in the `DiceGame.sol` contract in `packages/hardhat/contracts` | ||
|
||
π You will not be changing any code in the `DiceGame.sol` contract in this challenge. You will write your own contract to predict the outcome, then only roll the dice when it is favourable. | ||
|
||
πΈ Grab some funds from the faucet and roll the dice a few times. Watch the balance of the DiceGame contract in the Debug tab. It increases on a failed roll and decreases by the prize amount on a successful roll. | ||
|
||
 | ||
|
||
### π₯ Goals | ||
|
||
- [ ] Track the solidity code to find out how the DiceGame contract is generating random numbers. | ||
- [ ] Is it possible to predict the random number for any given roll? | ||
|
||
--- | ||
|
||
## Checkpoint 2: π Rigged Contract | ||
|
||
Start by creating a `receive()` function in the `RiggedRoll.sol` contract to allow it to receive Eth. This will allow us to fund the RiggedRoll contract from the faucet which is required for our contract to call the `rollTheDice()` function. | ||
|
||
Next add a `riggedRoll()` function. This function should predict the randomness of a roll, and if the outcome will be a winner, call `rollTheDice()` on the DiceGame contract. | ||
|
||
π Predict the outcome by generating your random numbers in the exact same way as the DiceGame contract. | ||
|
||
> π£ Reminder! Calling `rollTheDice()` will fail unless you send a message value of at least .002 Eth! [Here is one example of how to send value with a function call.](https://ethereum.stackexchange.com/questions/6665/call-contract-and-send-value-from-solidity) | ||
π To deploy your RiggedRoll contract, uncomment the appropriate lines in the `01_deploy_riggedRoll.ts` file in `packages/hardhat/deploy` | ||
|
||
πΈ You will need to send some funds to your RiggedRoll contract before doing your first roll, you can use the Faucet button at the bottom left of the page. | ||
|
||
β If you're struggling to get the exact same random number as the DiceGame contract, try adding some `console.log()` statements in both contracts to help you track the values. These messages will appear in the Hardhat node terminal. | ||
|
||
### βοΈ Side Quest | ||
|
||
- [ ] Add a statement to require `address(this).balance >= .002 ether` in your riggedRoll function. This will help prevent calling the `rollTheDice()` function without enough value. | ||
- [ ] Uncomment the code in `packages/nextjs/app/dice/page.tsx` to show a riggedRoll button and contract balance on the main UI tab. Now you can test your function without switching tabs. | ||
- [ ] Does your riggedRoll function only call `rollTheDice()` when it's going to be a winning roll? What happens when it does call `rollTheDice()`? | ||
|
||
 | ||
|
||
--- | ||
|
||
## Checkpoint 3: π΅ Where's my money?!? | ||
|
||
You have beaten the game, but where is your money? Since the RiggedRoll contract is the one calling `rollTheDice()`, that is where the prize money is being sent. | ||
|
||
 | ||
|
||
π₯ Create a `withdraw(address _addr, uint256 _amount)` function to allow you to send Eth from RiggedRoll to another address. | ||
|
||
### π₯ Goals | ||
|
||
- [ ] Can you send value from the RiggedRoll contract to your front end address? | ||
- [ ] Is anyone able to call the withdraw function? What would be the downside to that? | ||
|
||
### βοΈ Side Quest | ||
|
||
- [ ] Lock the withdraw function so it can only be called by the owner. | ||
|
||
 | ||
|
||
> β οΈ But wait, I am not the owner! You will want to set your front end address as the owner in `01_deploy_riggedRoll.ts`. This will allow your front end address to call the withdraw function. | ||
## Checkpoint 4: πΎ Deploy your contracts! π° | ||
|
||
π‘ Edit the `defaultNetwork` to [your choice of public EVM networks](https://ethereum.org/en/developers/docs/networks/) in `packages/hardhat/hardhat.config.ts` | ||
|
||
π You will need to generate a **deployer address** using `yarn generate` This creates a mnemonic and saves it locally. | ||
|
||
π©βπ Use `yarn account` to view your deployer account balances. | ||
|
||
β½οΈ You will need to send ETH to your **deployer address** with your wallet, or get it from a public faucet of your chosen network. | ||
|
||
π Run `yarn deploy` to deploy your smart contract to a public network (selected in `hardhat.config.ts`) | ||
|
||
> π¬ Hint: You can set the `defaultNetwork` in `hardhat.config.ts` to `sepolia` **OR** you can `yarn deploy --network sepolia`. | ||
--- | ||
|
||
## Checkpoint 5: π’ Ship your frontend! π | ||
|
||
βοΈ Edit your frontend config in `packages/nextjs/scaffold.config.ts` to change the `targetNetwork` to `chains.sepolia` or any other public network. | ||
|
||
π» View your frontend at http://localhost:3000 and verify you see the correct network. | ||
|
||
π‘ When you are ready to ship the frontend app... | ||
|
||
π¦ Run `yarn vercel` to package up your frontend and deploy. | ||
|
||
> Follow the steps to deploy to Vercel. Once you log in (email, github, etc), the default options should work. It'll give you a public URL. | ||
> If you want to redeploy to the same production URL you can run `yarn vercel --prod`. If you omit the `--prod` flag it will deploy it to a preview/test URL. | ||
> π¦ Since we have deployed to a public testnet, you will now need to connect using a wallet you own or use a burner wallet. By default π₯ `burner wallets` are only available on `hardhat` . You can enable them on every chain by setting `onlyLocalBurnerWallet: false` in your frontend config (`scaffold.config.ts` in `packages/nextjs/`) | ||
#### Configuration of Third-Party Services for Production-Grade Apps. | ||
|
||
By default, π Scaffold-ETH 2 provides predefined API keys for popular services such as Alchemy and Etherscan. This allows you to begin developing and testing your applications more easily, avoiding the need to register for these services. | ||
This is great to complete your **SpeedRunEthereum**. | ||
|
||
For production-grade applications, it's recommended to obtain your own API keys (to prevent rate limiting issues). You can configure these at: | ||
|
||
- π·`ALCHEMY_API_KEY` variable in `packages/hardhat/.env` and `packages/nextjs/.env.local`. You can create API keys from the [Alchemy dashboard](https://dashboard.alchemy.com/). | ||
|
||
- π`ETHERSCAN_API_KEY` variable in `packages/hardhat/.env` with your generated API key. You can get your key [here](https://etherscan.io/myapikey). | ||
|
||
> π¬ Hint: It's recommended to store env's for nextjs in Vercel/system env config for live apps and use .env.local for local testing. | ||
--- | ||
|
||
## Checkpoint 6: π Contract Verification | ||
|
||
Run the `yarn verify --network your_network` command to verify your contracts on etherscan π° | ||
|
||
π Search this address on Etherscan to get the URL you submit to πββοΈ[SpeedRunEthereum.com](https://speedrunethereum.com). | ||
|
||
--- | ||
|
||
> π Head to your next challenge [here](https://speedrunethereum.com). | ||
> π¬ Problems, questions, comments on the stack? Post them to the [π scaffold-eth developers chat](https://t.me/joinchat/F7nCRK3kI93PoCOk) |
Oops, something went wrong.