Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Written lesson cleanup: Storage Factory #214

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions courses/solidity/1-simple-storage/10-mappings/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _You can follow along with the video course from here._

### Introduction

We have just created a contract that stores multiple `Person`'s' names and favorite numbers in a list. In this session, you will learn about mappings, their functionality, and when it is more advantageous to use them.
We have just created a contract that stores multiple `Person`'s names and favorite numbers in a list. In this session, you will learn about mappings, their functionality, and when it is more advantageous to use them.

### Avoiding Costly Iterations

Expand All @@ -18,9 +18,8 @@ list_of_people.add(Person("John", 8));
list_of_people.add(Person("Mariah", 10));
list_of_people.add(Person("Chelsea", 232));

/* go through all the people to check their favorite number.
If name is "Chelsea" -> return 232
*/
// Go through all the people to check their favorite number.
// If name is "Chelsea" -> return 232
```

Iterating through a long list of data is usually expensive and time-consuming, especially when we do not need to access elements by their index.
Expand All @@ -42,10 +41,10 @@ nameToFavoriteNumber[_name] = _favoriteNumber;
```

> 👀❗**IMPORTANT**:br
> Mappings have a constant time complexity for lookups, meaning that retrieving a value by its key is done in constant time,
> Mappings have a constant time complexity for lookups, meaning that retrieving a value by its key is done in constant time.

> 🗒️ **NOTE**:br
> The default value for all key types is zero. In our case, `nameToFavoriteNumber["ET"]` will be equal to 0.
> The default value for all key types is zero. In our case, `nameToFavoriteNumber["ET"]` equals 0.

### Conclusion

Expand Down
8 changes: 4 additions & 4 deletions courses/solidity/1-simple-storage/11-deploying/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ _You can follow along with the video course from here._
Over the past eight lessons, we crafted the `SimpleStorage` contract. It defines a custom type `Person`, includes an internal variable that can be read and updated, and contains a public array and mapping that can also be modified. In this lesson, we will deploy the contract to a **real testnet**, which fully simulates a live blockchain environment without using real Ether.

> 🔥 **CAUTION**:br
> You could be tempted to immediately deploy this contract to a testnet. As a general rule, I caution against this. Make sure to write tests, carry out audits and ensure the robustness of your contract before deploying it to production. However, for the sake of this demonstration, we're going to deploy this as a dummy contract on a testnet.
> You could be tempted to immediately deploy this contract to the mainnet. As a general rule, I caution against this. Make sure to write tests, carry out audits and ensure the robustness of your contract before deploying it to production. However, for the sake of this demonstration, we're going to deploy this as a dummy contract on a testnet.

Before deploying, be always sure to make a **compilation check**. This ensures that the contract has no errors or warnings and is fit for deployment.
Before deploying, be always sure to make a **compilation check**. This ensures that the contract has no errors or warnings, and is fit for deployment.

### Deployment on a testnet

Expand All @@ -37,9 +37,9 @@ Since the contract has been deployed, we can now interact with it and **update t
> 👀❗**IMPORTANT**:br
> View and pure functions will not send transactions

> 💡 **TIP**:br > _Celebrate small victories and milestones. These psychological boosts will keep you engaged in the learning process._
> 💡 **TIP**:br _Celebrate small victories and milestones. These psychological boosts will keep you engaged in the learning process._

It's possible to deploy a contract to different testnets or a real mainnet, just by switching the Metamask network. Be sure to have enough net-compatible ETHs to deploy your contract.
It's possible to deploy a contract to different testnets or a real mainnet, just by switching the MetaMask network. Be sure to have enough net-compatible ETHs to deploy your contract.

### Conclusion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _Follow along with the video_

### Introduction

With the rising costs of deploying to the Ethereum mainnet, scaling solutions like roll-ups and Layer 2 networks are increasingly in demand. The following lessons will guide you through deploying a smart contract to L2 zkSync. If you've followed the zkSync lessons on the **Blockchain Basics** section, you should have already added ZK-Sync to your Metamask. If not, we'll walk through that process in the next lesson.
With the rising costs of deploying to the Ethereum mainnet, scaling solutions like roll-ups and Layer 2 networks are increasingly in demand. The following lessons will guide you through deploying a smart contract to L2 zkSync. If you've followed the zkSync lessons on the **Blockchain Basics** section, you should have already added ZKsync to your MetaMask. If not, we'll walk through that process in the next lesson.

### Testnet Funds

Expand All @@ -19,4 +19,4 @@ To deploy contracts on zkSync, you'll need testnet funds. There are two methods

### Deploying

To deploy a contract to ZK-Sync, there are a few key steps to follow. First, it's crucial to configure zkSync in your Metamask wallet. Next, you'll need to acquire testnet ETH, which is necessary for deploying and testing your contract.
To deploy a contract to ZKsync, there are a few key steps to follow. First, it's crucial to configure zkSync in your MetaMask wallet. Next, you'll need to acquire testnet ETH, which is necessary for deploying and testing your contract.
4 changes: 2 additions & 2 deletions courses/solidity/1-simple-storage/18-evm-recap/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ In this section, we'll quickly summarize the lessons from 1 to 9 and learn about
### EVM

EVM stands for _Ethereum Virtual Machine_. It's a decentralized computational engine that executes smart contracts.
Any contract that it's written in Solidity, can be deployed to any EVM-compatible blockchain. Examples of such blockchains and Layer 2 solutions include **Ethereum**, **Polygon**, **Arbitram**, **Optimism**, and **Zksync**.
Any contract that it's written in Solidity, can be deployed to any EVM-compatible blockchain. Examples of such blockchains and Layer 2 solutions include **Ethereum**, **Polygon**, **Arbitrum**, **Optimism**, and **ZKsync**.

> 🚧 **WARNING**:br
> Although a blockchain like Zksync may be EVM-compatible, it is essential to verify that all Solidity keywords are supported
> Although a blockchain like ZKsync may be EVM-compatible, it is essential to verify that all Solidity keywords are supported

### Contract Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In the top right corner of the lesson view, you'll find a link to the [**GitHub

Next to the video lesson, there is a **written lesson** tab 📝. This tab provides the course content in text format, which is useful for reading along, copy-pasting code snippets or reviewing updates.

If you're watching on YouTube, links to these resources are available in the video description. However, watching this course on Cyphrin Updraft offers additional benefits like tracking your progress and accessing written lessons, which will enhance your learning experience.
If you're watching on YouTube, links to these resources are available in the video description. However, watching this course on Cyfrin Updraft offers additional benefits like tracking your progress and accessing written lessons, which will enhance your learning experience.

### Best Practices for Learning

Expand Down
2 changes: 1 addition & 1 deletion courses/solidity/1-simple-storage/3-introduction/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The repository serves two main purposes:

#### Asking Questions

It’s very likely that during your journey you’ll have questions. It’s recommended to use the [**Q&A**](https://github.com/Cyfrin/foundry-full-course-f23/discussions/new?category=q-a) section provided inside the discussion tab. You will be guided into how to best formulate your dubts and queries, such that have the highest chance of being answered by the community, AI or a forum.
It’s very likely that during your journey you’ll have questions. It’s recommended to use the [**Q&A**](https://github.com/Cyfrin/foundry-full-course-f23/discussions/new?category=q-a) section provided inside the discussion tab. You will be guided into how to best formulate your doubts and queries, such that have the highest chance of being answered by the community, AI or a forum.

### Setting Up

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ Well done! You just created and compiled your first smart contract in Solidity.
### 🧑‍💻 Test yourself

1. 📕 What does IDE mean and what are Remix main features?
2. 📕 What's the keywork `pragma` used for?
2. 📕 What's the keyword `pragma` used for?
3. 📕 Explain what compiling a contract means.
4. 🧑‍💻 Write an empty contract that contains a SPDX License Identifier and compiles with version 0.8.11 or 0.8.13.
8 changes: 4 additions & 4 deletions courses/solidity/1-simple-storage/5-basic-types/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Solidity supports various _elementary_ types that can be combined to create more
- Boolean (bool): true or false
- Unsigned Integer (uint): unsigned whole number (positive)
- Integer (int): signed whole number (positive and negative)
- Address (address): 20 bytes value. An example of an address can be found within your Metamask account.
- Address (address): 20 bytes value. An example of an address can be found within your MetaMask account.
- Bytes (bytes): low-level raw byte data

### Variables definition

Variables are just placeholders for **values**. A value can be one **data type** described in the list above. For instance, we could create a Boolean variable named `hasFavoriteNumber`, which would represent whether someone has a favourite number or not (constant `true` or `false`).

```solidity
bool hasFavoriteNumber = true; //the variable hasFavoriteNumber` represents the value `true`
bool hasFavoriteNumber = true; // The variable `hasFavoriteNumber` represents the value `true`
```

It's possible to specify the number of **bits** used for `uint` and `int`. For example, uint256 specifies that the variable has 256 bits. uint is a shorthand for uint256.
Expand All @@ -37,7 +37,7 @@ The _semicolon_ at the end of each line signifies that a statement is completed.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract Simple Storage{
contract SimpleStorage {
// Basic types
bool hasFavoriteNumber = true;
uint256 favoriteNumber = 88;
Expand All @@ -60,7 +60,7 @@ bytes dynamicBytes = "I am a dynamic array, so you can manipulate my size";

Bytes can be allocated in size (up to `bytes32`). However, bytes and bytes32 represent distinct data types.

**Strings** are internally represented as _dynamic byte arrays_ (`bytes` tipe) and designed specifically for working with text. For this reason, a string can easily be converted into bytes.
**Strings** are internally represented as _dynamic byte arrays_ (`bytes` type) and designed specifically for working with text. For this reason, a string can easily be converted into bytes.

[Bits and Bytes overview](https://www.youtube.com/watch?v=Dnd28lQHquU)

Expand Down
8 changes: 4 additions & 4 deletions courses/solidity/1-simple-storage/6-functions/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If we open the Remix terminal we can see that deploying the contract has just se

Let's send a transaction to the `store` function to change the value of the variable `favoriteNumber`: you can insert a number and press the `store` button in Remix. A transaction is initiated and after some time, its status will change from pending to complete.

💸 From the accounts section, it becomes visible that ETH is being consumed every time a transaction is submitted. When the state of the blockchain is modified (e.g. deploying a contract, sending ETH, ..), is done by sending a transaction that consumes **gas**. Executing the `store` function is more expensive than just transferring ETH between accounts, with the rising gas expenses primarily associated (though not exclusively) with the code length.
💸 From the accounts section, it becomes visible that ETH is being consumed every time a transaction is submitted. When the state of the blockchain is modified (e.g. deploying a contract, sending ETH, ...), is done by sending a transaction that consumes **gas**. Executing the `store` function is more expensive than just transferring ETH between accounts, with the rising gas expenses primarily associated (though not exclusively) with the code length.

#### Verifying the stored value

Expand All @@ -73,7 +73,7 @@ This contract is missing a way to check if the number has been updated: now we c
The default visibility of the `favoriteNumber` variable is **internal**, preventing external contracts and users from viewing it.

> 🗒️ **NOTE**:br
> Appending the `public` keyword next to a variable will automatically change its visibility and it will generate a **get function**.
> Appending the `public` keyword next to a variable will automatically change its visibility and it will generate a **getter function** (a function that gets the variable's value when called).

```solidity
uint256 public favoriteNumber;
Expand All @@ -99,13 +99,13 @@ If a visibility specifier is not given, it defaults to `internal`.
The terms `view` and `pure` are used when a function reads values from the blockchain without altering its state. Such functions will not initiate transactions but rather make calls, represented as blue buttons in the Remix interface. A `pure` function will prohibit any reading from the state or storage.

```solidity
function retrieve() public view returns(uint256){
function retrieve() public view returns(uint256) {
return favoriteNumber;
}
```

```solidity
function retrieve() public pure returns(uint256){
function retrieve() public pure returns(uint256) {
return 7;
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _You can follow along with the video course from here._

### Introduction

Up to this point, the `SimpleStorage` contract allows for storing, updating, and viewing a single favorite number. In this lesson, we'll enhance the code to store multiple numbers, enabling more than one person to store their values. We'll learn how to create a list of favorite numbers using **arrays**, and we'll explore the **`structs`** keyword for creating new types in Solidity.
Up to this point, the `SimpleStorage` contract allows for storing, updating, and viewing a single favorite number. In this lesson, we'll enhance the code to store multiple numbers, enabling more than one person to store their values. We'll learn how to create a list of favorite numbers using **arrays**, and we'll explore the **`struct`** keyword for creating new types in Solidity.

### Arrays and struct

Expand All @@ -23,7 +23,7 @@ uint256[] list_of_favorite_numbers = [0, 78, 90];
```

> 🗒️ **NOTE**:br
> Arrays are zero-indexed: the first element is at position zero (0), the second is position (index) 1, and so on.
> Arrays are zero-indexed: the first element is at position zero (has index 0), the second element is at position one (has index 1), and so on.

The issue with this data structure is that we cannot link the owner with its favorite value. One solution is to establish a **new type** using the `struct` keyword, named `Person`, which is made of two _attributes_: a favorite number and a name.

Expand All @@ -43,7 +43,7 @@ From this struct, we can instantiate a variable `my_friend` that has the type `P
Person public my_friend = Person(7, 'Pat');
/* equals to
Person public my_friend = Person({
favoriteNumber:7,
favorite_number:7,
name:'Pat'});
*/
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We can input the compiler error under the drop-down menu, execute the search, an

::image{src='/solidity/remix/lesson-2/errors-warnings/phind-answer.png' style='width: 100%; height: auto;'}

#### Othe resources
#### Other resources

It is advised to make active use of AI tools, as they can substantially boost your understanding and skills. Later in this course, we will explore how to ask effective questions, utilize AI prompts, structure your inquiries, and improve your search and learning techniques.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ In our contract, the variable `myFavoriteNumber` is a storage variable. Variable

```solidity
contract MyContract {
uint256 favoriteNumber; //this is a storage variable
uint256 favoriteNumber; // this is a storage variable
};
```

Expand All @@ -73,7 +73,7 @@ In Solidity, a `string` is recognized as an **array of bytes**. On the other han
> You can't use the `storage` keyword for variables inside a function. Only `memory` and `calldata` are allowed here, as the variable only exists temporarily.

```solidity
function addPerson(string memory _name, uitn256 _favoriteNumber) public { //cannot use storage as input parameters
function addPerson(string memory _name, uitn256 _favoriteNumber) public { // cannot use storage as input parameters
uint256 test = 0; // variable here can be stored in memory or stack
listOfPeople.push(Person(_favoriteNumber, _name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _You can follow along with the video course from here._

### Introduction

You can find the code for this section in the [Remix Storage Factory Github repository](https://github.com/cyfrin/remix-storage-factory-f23). In these nine lessons we'll work with three new contracts:
You can find the code for this section in the [Remix Storage Factory Github repository](https://github.com/cyfrin/remix-storage-factory-f23). In these nine lessons, we'll work with three new contracts:

1. `SimpleStorage.sol` - the contract we build in the previous section, with some modifications
2. `AddFiveStorage.sol` - a child contract of `SimpleStorage` that leverages _inheritance_
Expand All @@ -30,8 +30,6 @@ It's possible to interact with this newly deployed `SimpleStorage` via the `stor

The **`sfGet`** function, when given the input '0', will indeed return the number provided by the previous function. The **address** of the `SimpleStorage` contract can then be retrieved by clicking on the get function `listOfSimpleStorageContracts`.

::image{src='/solidity/remix/lesson-3/setting-up/graph-1.png' style='width: 100%; height: auto;'}

### Conclusion
The `StorageFactory` contract manages numerous instances of an external contract `SimpleStorage`. It provides functionality to deploy new contract instances dynamically and allows for the storage and retrieval of values from each instance. These instances are maintained and organized within an array, enabling efficient tracking and interaction.

Expand Down