Skip to content

Commit 5a66104

Browse files
committed
Draft deeper guidance to learner in lesson body until line 239
1 parent 6161e6b commit 5a66104

File tree

1 file changed

+21
-22
lines changed
  • pages/lessons/projects

1 file changed

+21
-22
lines changed

pages/lessons/projects/3.mdx

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ differentiate between different levels or categories in that service. Think of s
3131
streaming services out there such as Netflix, Disney+, etc. Some have different levels
3232
of access depending on the subscription. We want to let users access different
3333
services depending on the NFT they mint and own.
34+
I'M NOT AT ALL SURE WHAT WE ARE BUILDING..... MAKE SURE WE ADD THAT WE'LL BE INHERITING A FEW MORE OZ CONTRACTS ThIS TIME. MAYBE A NUDGE TO LEARNER TO READ SOME OF THE OZ CODE?
3435

3536
![1_diagram.png](/assets/lessons/3/1_diagram.png)
3637

3738
## First things first 👷‍♂️
3839

3940
Before we start coding, we need to create our project template. We are going to follow
4041
the same steps as in previous lessons. Using our package manager (npm, yarn,
41-
etc) we create a Hardhat project and remove unnecessary files.
42+
etc)WE ARE ONLY USING ONE we create a Hardhat project and remove unnecessary files.
4243

4344
If you’ve done our previous lesson, it’s the exact same process. Make a note of
4445
remembering these steps and what they do, for we will use them a lot in
4546
the future.
4647

47-
Let’s first open a console and cd into our `d_d_academy` folder, or create it
48-
first if you don't have it. Then let's create a folder for our NFT project:
48+
Let’s first open a console and `cd` into our `d_d_academy` folder, or create it
49+
first if you don't have it. Then let's create a folder for our NFT project and make sure to `cd` into it too:
4950

5051
```bash
5152
## (OPTIONAL) create a folder for our D_D Academy projects
@@ -100,22 +101,22 @@ install them manually with:
100101
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-chai-matchers
101102
```
102103
</Callout>
104+
In a Hardhat project, the default folders are supposed to be for:
105+
106+
- `contracts/` is where the source files for your contracts should be.
107+
- `scripts/` is where simple automation scripts go.
108+
- `test/` is where your tests should go.
103109
104-
We delete some files so we start fresh:
110+
We want to delete some of the default files so we start fresh, e.g. we will create our own .sol file for our contract, etc:
105111
106112
```bash
107113
rm contracts/*.sol
108114
rm scripts/*.js
109115
rm test/*.js
110116
```
111117
112-
In a Hardhat project, the default folders are supposed to be for:
113118
114-
- `contracts/` is where the source files for your contracts should be.
115-
- `scripts/` is where simple automation scripts go.
116-
- `test/` is where your tests should go.
117-
118-
We now need to add our last dependency (OpenZeppelin contracts):
119+
We now need to add our last dependency. The OpenZeppelin contracts:
119120
120121
```bash
121122
npm install @openzeppelin/contracts
@@ -135,7 +136,7 @@ Fire up your code editor and let’s start hacking. I’m using VSCode, so I run
135136
`code .` in my terminal.
136137
137138
Let’s create an empty file named `TierNFT.sol` inside the `contracts/` folder
138-
and copy this code inside:
139+
and following the contract and file naming convention, create a contract of the same name:
139140
140141
```solidity
141142
// SPDX-License-Identifier: MIT
@@ -145,19 +146,18 @@ contract TierNFT {
145146
}
146147
```
147148
148-
Now that we have our License, the version of solidity we are using and the
149+
Now that we have our license, the version of Solidity we are using and the
149150
contract set up, we can add the logic and the variables we need to store.
150151
151-
## What do we need?
152+
## What do we need?
153+
### we sort of need this 'intro' at the start of the lesson......
152154
153155
As we are creating tiers for the categories of our NFTs, we need to also store
154-
information about tiers in our contracts.
155-
156-
We'll write our smart contract step by step in four stages.
156+
information about tiers in our contracts. We'll write our smart contract step by step in four stages.
157157

158158
### Inheriting OpenZeppelin ERC721 and adding a Mint Function
159159

160-
Let’s get started with a simple contract, inheriting OpenZeppelin ERC721 like we did last time.
160+
Let’s get started by inheriting OpenZeppelin's ERC721.sol like we did last time. We add a constructor to our contract, which will mirror the one from ERC721.sol.
161161
162162
```solidity
163163
// SPDX-License-Identifier: MIT
@@ -173,9 +173,8 @@ contract TierNFT is ERC721 {
173173
}
174174
```
175175
176-
We add a constructor to our contract, which will mirror the one inherited from ERC721.sol. If we had no constructor, the compiler would throw errors.
177176
178-
Now let’s go ahead and add a mint function that only uses `_safeMint` **i don't understand 'only uses'....as opposed to what?**'
177+
Now let’s go ahead and add a mint function which will call `_safeMint` from the inherited contract, and we'll make it `payable`. We'll see why shortly. Can you remember what `++` does to our total supply?
179178
180179
```solidity
181180
// SPDX-License-Identifier: MIT
@@ -201,7 +200,7 @@ contract TierNFT is ERC721 {
201200
202201
### Adding Tiers and Using Them in the Mint Function
203202
204-
Now add the tiers and assign their values, where each one represents a service subscription.
203+
Now to make our code neat and easily readable, just before the contract declaration, add the tiers, and assign their values, where each one represents a service subscription. Note that we assign the `constant` keyword, which is what it sounds like - the values won't change, which in turn cuts down a lot on gas costs. Always good to know, but we'll go into 'gas optimisation' for you in a future lesson.
205204
206205
```solidity
207206
// SPDX-License-Identifier: MIT
@@ -234,9 +233,9 @@ contract TierNFT is ERC721 {
234233
}
235234
````
236235
237-
We have added `Basic`, `Medium` and `Premium` as tiers and assigned their values. We store what tier each NFT holds in `mapping(uint256 => uint256) public tokenTier;`.
236+
We have added `Basic`, `Medium` and `Premium` as tiers and assigned their values. We store which tier each NFT holds in `mapping(uint256 => uint256) public tokenTier;`. Mappings are widely used in Solidity, having many advantages. For example, they are a great way to store batches of data and access them efficiently and therefore cheaply through 'key: value' pairs.
238237
239-
Now we need to modify the mint function for the tier NFTs:
238+
Now we need to modify the mint function with logic to be able to actually access the three tiers of the NFTs separately. We use a 'conditional' `if/else if` statement to achieve this. If you know Javascript, you know `if`, and you know `else`!
240239
241240
```solidity
242241
// constructor part of the code...

0 commit comments

Comments
 (0)