From c0f59dce087e5c6d6e8ebac28dee29a828dc04e7 Mon Sep 17 00:00:00 2001 From: Lucas Leclerc Date: Sun, 19 May 2024 14:08:26 +0200 Subject: [PATCH 1/7] feat(p2p): add explanations to step 2 --- p2p/5.Create_an_ERC-20/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/5.Create_an_ERC-20/README.md b/p2p/5.Create_an_ERC-20/README.md index e45d5e97..7f5f9ec9 100644 --- a/p2p/5.Create_an_ERC-20/README.md +++ b/p2p/5.Create_an_ERC-20/README.md @@ -69,6 +69,7 @@ In this step, you will create the variables, the mappings and the constructor ne - Initialize `_totalSupply` in the [constructor](https://docs.soliditylang.org/en/v0.8.21/contracts.html#constructor) of the contract. > ⚠️ Don't forget to assign `_totalSupply` to a wallet and to emit an event +> All the events you need to emit are already defined in the [interface](./utils/IERC20.sol). Find the right one. ### 📚 **Documentation**: From db3f0176e2ba4e82439ecca5136ad4b8ff0b1195 Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 00:25:03 +0200 Subject: [PATCH 2/7] update: SETUP.md --- p2p/5.Create_an_ERC-20/SETUP.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/p2p/5.Create_an_ERC-20/SETUP.md b/p2p/5.Create_an_ERC-20/SETUP.md index 773f79ed..63ba360d 100644 --- a/p2p/5.Create_an_ERC-20/SETUP.md +++ b/p2p/5.Create_an_ERC-20/SETUP.md @@ -1,17 +1,21 @@ -# Setup - Foundry +# Setup - Foundry & VSCode extension [Foundry](https://book.getfoundry.sh/) is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. We will need it throughout the workshop. ## Download foundry - Open your terminal and type + ```bash curl -L https://foundry.paradigm.xyz | bash ``` -. This will download `foundryup`. + +This will download foundryup. + - Then, you can download foundry by running `foundryup` - If everything went fine you should be able to use `forge`, `anvil`, `chisel` and `cast`. - If you are on macos you will need to install `libusb` with + ```bash brew install libusb ``` @@ -24,18 +28,21 @@ forge --version It should print your current version. -If you have some troubles during the installation, you can refer to the [official documentation](https://github.com/foundry-rs/foundry#installation). +If you have some troubles during the installation, you can refer to the [official documentation](https://book.getfoundry.sh/getting-started/installation). ## Create a foundry project Once everything is done, you can create a new project using + ```bash forge init new_project cd new_project ``` + This should create a new directory with a brand new foundry project If you already have a repository, you might need to add + ```bash --no-commit ``` @@ -43,31 +50,25 @@ If you already have a repository, you might need to add The first thing you wants to do is set the solidity version of this project in the `foundry.toml` file wich is the configuration file of foundry. You can do this by adding in the "[profile.default]" section: + ```toml solc_version = "0.8.20" ``` ## VSCode Integration -I recommend you to install [solidity vscode extension](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity), it is an extension that simplifies development in Solidity. +I recommand you to install [solidity vscode extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity), it is an extension that simplifies development in Solidity. -To be able to use it natively with foundry, you are going to do a few steps: +Also, I recommand you to use the extension formatter. It will format your code on save, which allows you to have a clean codebase. To do so: -- Generate the remappings.txt using this command -```bash -forge remappings > remappings.txt -``` - Create a `.vscode/settings.json` file with this content + ```json { "editor.formatOnSave": true, - "solidity.packageDefaultDependenciesContractsDirectory": "src", - "solidity.packageDefaultDependenciesDirectory": "lib", - "solidity.compileUsingRemoteVersion": "v0.8.20", "[solidity]": { - "editor.defaultFormatter": "JuanBlanco.solidity" - }, - "solidity.formatter": "forge", + "editor.defaultFormatter": "NomicFoundation.hardhat-solidity" + } } ``` From 9d2759c9cbcba415044ef80d45a14c2623601843 Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 00:26:03 +0200 Subject: [PATCH 3/7] add: explanation on data location and units in Solidity --- p2p/5.Create_an_ERC-20/Solidity.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/p2p/5.Create_an_ERC-20/Solidity.md b/p2p/5.Create_an_ERC-20/Solidity.md index 1f848a31..2f9d3892 100644 --- a/p2p/5.Create_an_ERC-20/Solidity.md +++ b/p2p/5.Create_an_ERC-20/Solidity.md @@ -7,7 +7,7 @@ ## Contracts - **Contracts**: The building blocks of Ethereum smart contracts. - - [Solidity by Example - Hello World](https://solidity-by-example.org/hello-world/) + - [Solidity by Example - Hello World](https://solidity-by-example.org/hello-world/) ## Data Types and State Variables @@ -24,6 +24,13 @@ - **private**: Accessible only within the contract. - [Solidity by Example - Visibility](https://solidity-by-example.org/visibility/) +## Data Location + +- **Storage**: Persistent data stored on the blockchain. +- **Memory**: Temporary data stored during function execution. +- **Stack**: Local variables stored in function execution context. + - [Solidity by Example - Data Location](https://solidity-by-example.org/data-location/) + ## Mappings and Arrays - **Mappings**: Key-value data structures. @@ -34,7 +41,7 @@ ## Functions - **Functions**: Code blocks within contracts that execute specific tasks. - - [Solidity by Example - Functions](https://solidity-by-example.org/function/) + - [Solidity by Example - Functions](https://solidity-by-example.org/function/) ## Constructor @@ -61,6 +68,11 @@ - **Events**: Enable logging of important contract actions for external consumption. - [Solidity by Example - Events](https://solidity-by-example.org/events/) +## Units + +- **Units**: Ether and Wei are the primary units of Ethereum. 1 ether = 10^18 wei. + - [Solidity by Example - Units](https://solidity-by-example.org/ether-units/) + ## Solidity by Example - To find more examples of practical Solidity implementations, explore [Solidity by Example](https://solidity-by-example.org/). From f75a052a7138de53f59a12160404c42af6e3dcd3 Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 00:35:51 +0200 Subject: [PATCH 4/7] update: step2 create erc-20 --- p2p/5.Create_an_ERC-20/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/p2p/5.Create_an_ERC-20/README.md b/p2p/5.Create_an_ERC-20/README.md index 7f5f9ec9..9c84ae0d 100644 --- a/p2p/5.Create_an_ERC-20/README.md +++ b/p2p/5.Create_an_ERC-20/README.md @@ -55,7 +55,7 @@ In this step, you will create the variables, the mappings and the constructor ne ### 📌 **Tasks**: - Create in the `ERC20` contract the following variables: - - All variables except `_totalSupply` will be defined on declaration + - All variables except `_totalSupply` will be initialized on declaration - `name` which corresponds to the name of the token - `symbol` which corresponds to the abbreviation of the token name - `decimals` which corresponds to the number of decimals that the token can have @@ -67,9 +67,14 @@ In this step, you will create the variables, the mappings and the constructor ne - `_allowances` which corresponds to the number of tokens whose owner has authorized the spender to use > ⚠️ Take care about the [visibility](https://docs.soliditylang.org/en/v0.8.21/contracts.html#state-variable-visibility) of your mappings! +I give you the last one, it's a little more complicated: + +```solidity +mapping(address owner => mapping(address spender => uint256)) private _allowances; +``` + - Initialize `_totalSupply` in the [constructor](https://docs.soliditylang.org/en/v0.8.21/contracts.html#constructor) of the contract. -> ⚠️ Don't forget to assign `_totalSupply` to a wallet and to emit an event -> All the events you need to emit are already defined in the [interface](./utils/IERC20.sol). Find the right one. +> ⚠️ Don't forget to assign `_totalSupply` to a wallet and to emit an event. All the events you need to emit are already defined in the [interface](./utils/IERC20.sol). Find the right one. ### 📚 **Documentation**: From 71bd0eb897aec2af9455a68bca077bbb1152039e Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 01:38:20 +0200 Subject: [PATCH 5/7] update: replace Mumbai deprecated testnet by Sepolia --- p2p/5.Create_an_ERC-20/README.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/p2p/5.Create_an_ERC-20/README.md b/p2p/5.Create_an_ERC-20/README.md index 9c84ae0d..e86b4c93 100644 --- a/p2p/5.Create_an_ERC-20/README.md +++ b/p2p/5.Create_an_ERC-20/README.md @@ -146,25 +146,28 @@ If not, fix the function implementation. ### 📑 **Description**: -In this step, you will deploy your ERC-20 on [Polygon's Mumbai Testnet](https://www.alchemy.com/overviews/mumbai-testnet). Testing our contract on a testnet allows us to deploy and test our application on the Polygon network, a layer two of Ethereum, without having to spend real money. Be careful, this step requires a lot of tools. The first part of the tasks consists of the implementation of these tools and the second one of the deployment of the ERC-20. +In this step, you will deploy your ERC-20 on [Ethereum Sepolia Testnet](https://www.alchemy.com/overviews/sepolia-testnet). Testing our contract on a testnet allows us to deploy and test our application on the Ethereum network, without having to spend real money because we use test tokens. Be careful, this step requires a lot of tools. The first part of the tasks consists of the installation of these tools and the second one of the deployment of the ERC-20. ### 📌 **Tasks**: -- Download [Metamask](https://metamask.io) and create an account, if you don't already have one. +#### Installation of the tools + +- Download [Metamask](https://metamask.io) and create an account, if you don't already have one. It is the most popular Ethereum wallet and allows you to interact with the Ethereum blockchain. - Create your API key on [Alchemy](https://dashboard.alchemy.com/apps). - Sign in. - Click on `Create new app`. - Enter a name for your API key. - - Select `Polygon PoS` chain and `Polygon Mumbai` network. + - Select `Ethereum` chain and `Ethereum Sepolia` network. - Click on `Create app`. - Now, click on `API Key` and you can see your API key as well as your RPC URL in `HTTPS`. -- Add Mumbai Testnet network to Metamask, [here](https://www.alchemy.com/overviews/mumbai-testnet#how-to-get-started-using-the-mumbai-testnet) a doc to explain how to do it. -- Go to [Mumbai faucet](https://mumbaifaucet.com), enter your wallet address and send you MATIC. +- Add Sepolia Testnet network to Metamask, [here](https://moralis.io/how-to-add-the-sepolia-network-to-metamask-full-guide/) a doc to explain how to do it. +- Go to [Sepolia faucet](https://www.alchemy.com/faucets/ethereum-sepolia), enter your wallet address and send you ETH. +> ⚠️ You need to have some ETH on mainnet to give you test tokens. If you don't have any, call the workshop manager. - Copy the `.env` file which is in the `utils` folder to your project and complete the variables except the last one. -
+#### Deployment of the ERC-20 -The setup is now finished, let's go to the interesting part: deploy our ERC-20. +The setup is now finished, let's go to the interesting part: deploy our ERC-20. We will again use [foundry](https://book.getfoundry.sh/), the [forge create](https://book.getfoundry.sh/forge/deploying) command to deploy the contract and the [cast](https://book.getfoundry.sh/cast/) command to interact with it. - Load the environment variables: ``` @@ -189,7 +192,7 @@ cast call $CONTRACT_ADDRESS "totalSupply()" --rpc-url $RPC_URL ``` > 💡 This should display `100000` in hexadecimal -Now, you can go in Metamask on Mumbai Testnet, click on `Import tokens` and put the `CONTRACT_ADDRESS`. Congratulation! You have your own token in your metamask wallet. You can now do what you want with your tokens. +Now, you can go in Metamask on Sepolia Testnet, click on `Import tokens` and put the `CONTRACT_ADDRESS`. Congratulation! You have your own token in your metamask wallet. You can now do what you want with your tokens.
@@ -210,10 +213,10 @@ cast send $CONTRACT_ADDRESS "approve(address, uint256)" $WALLET 200 --private-ke ### 📚 **Documentation**: -- [Mumbai Testnet](https://www.alchemy.com/overviews/mumbai-testnet) +- [Ethereum Sepolia Testnet](https://www.alchemy.com/overviews/sepolia-testnet) - [Metamask](https://metamask.io) -- [Add Mumbai Testnet to Metamask](https://www.alchemy.com/overviews/mumbai-testnet#how-to-get-started-using-the-mumbai-testnet) -- [Mumbai faucet](https://mumbaifaucet.com/) +- [Add Sepolia Testnet to Metamask](https://moralis.io/how-to-add-the-sepolia-network-to-metamask-full-guide/) +- [Sepolia faucet](https://www.alchemy.com/faucets/ethereum-sepolia) - [Foundry deploy](https://book.getfoundry.sh/forge/deploying) - [Cast command](https://book.getfoundry.sh/cast/) @@ -227,7 +230,7 @@ I hope you enjoyed the workshop! You have discovered what an ERC-20 is but there are still many other concepts to discover, here are some examples: - Discovering what is an [ERC-721 contracts](https://eips.ethereum.org/EIPS/eip-721) (NFT) -- Deploy your ERC-20 on other blockchain, like [Sepolia](https://www.alchemy.com/overviews/sepolia-testnet) +- Deploy your ERC-20 on other blockchain, like [Polygon Amoy](https://polygon.technology/blog/introducing-the-amoy-testnet-for-polygon-pos) ## Authors From 0498f0e4895c5e2b6a3a92dbb1040a5258ca6fa5 Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 02:04:13 +0200 Subject: [PATCH 6/7] update: create-erc20 step5 --- p2p/5.Create_an_ERC-20/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/5.Create_an_ERC-20/README.md b/p2p/5.Create_an_ERC-20/README.md index e86b4c93..9400a168 100644 --- a/p2p/5.Create_an_ERC-20/README.md +++ b/p2p/5.Create_an_ERC-20/README.md @@ -190,7 +190,7 @@ source .env ```bash cast call $CONTRACT_ADDRESS "totalSupply()" --rpc-url $RPC_URL ``` -> 💡 This should display `100000` in hexadecimal +> 💡 This should display the total supply of your tokens in wei. Now, you can go in Metamask on Sepolia Testnet, click on `Import tokens` and put the `CONTRACT_ADDRESS`. Congratulation! You have your own token in your metamask wallet. You can now do what you want with your tokens. From 949b77d92a9af3648660e25f359040e20383bb1f Mon Sep 17 00:00:00 2001 From: Nathan FLATTIN Date: Mon, 20 May 2024 02:08:58 +0200 Subject: [PATCH 7/7] fix: breaking link --- p2p/5.Create_an_ERC-20/Solidity.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/5.Create_an_ERC-20/Solidity.md b/p2p/5.Create_an_ERC-20/Solidity.md index 2f9d3892..59678a6c 100644 --- a/p2p/5.Create_an_ERC-20/Solidity.md +++ b/p2p/5.Create_an_ERC-20/Solidity.md @@ -24,12 +24,12 @@ - **private**: Accessible only within the contract. - [Solidity by Example - Visibility](https://solidity-by-example.org/visibility/) -## Data Location +## Data Locations - **Storage**: Persistent data stored on the blockchain. - **Memory**: Temporary data stored during function execution. - **Stack**: Local variables stored in function execution context. - - [Solidity by Example - Data Location](https://solidity-by-example.org/data-location/) + - [Solidity by Example - Data Locations](https://solidity-by-example.org/data-locations/) ## Mappings and Arrays