Skip to content

Commit 42ef6ce

Browse files
committed
Make some textual changes
1 parent 8c01bfb commit 42ef6ce

File tree

1 file changed

+33
-34
lines changed
  • pages/lessons/projects

1 file changed

+33
-34
lines changed

pages/lessons/projects/3.mdx

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ In the previous lesson, we talked about NFTs and their use cases. Unlike traditi
4444
<Question question="lesson-2/1-intro/Q5" />
4545
</SideDrawer>
4646
<br/>
47+
4748
**Now that we have set the stage, it's time to dive into the exciting world of tiered NFTs and uncover the unique superpowers they possess. By the end of this tutorial, you will have gained a wealth of knowledge and accomplished the following steps**:
4849

4950
- Setting up the development environment
@@ -68,16 +69,15 @@ We will guide you through each step, ensuring a fun and comprehensive learning e
6869
## First things first 👷‍♂️
6970
{/* PART 2 ASSERTIONS AND DATA TYPES e.g. MAPPINGS */}
7071

71-
Before we start coding, we need to create our project template. We are going to follow
72-
the same steps as in previous lessons. Using `npm` as our package manager, we'll create
72+
Before we start coding, we need to create our project template by following
73+
the same steps as in the previous *Build a Basic NFT* lesson. Make a note of
74+
these steps and what they do, for you will use them a lot in
75+
the future. Using `npm` as our package manager, we'll create
7376
a Hardhat project and remove the default files we don't need.
7477

75-
If you’ve done our previous lesson, it’s the exact same process. Make a note of
76-
remembering these steps and what they do, for we will use them a lot in
77-
the future.
7878

7979
Let’s first open a console and `cd` into our `d_d_academy` folder, or create it
80-
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:
80+
first if you haven't already. Then create a folder for our TierNFT project and make sure to `cd` into it too:
8181

8282
```bash
8383
## (OPTIONAL) create a folder for our D_D Academy projects
@@ -132,13 +132,13 @@ install them manually with:
132132
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-chai-matchers
133133
```
134134
</Callout>
135-
In a Hardhat project, the default folders are supposed to be for:
135+
In a Hardhat project, some of the default folders are:
136136
137-
- `contracts/` is where the source files for your contracts should be.
138-
- `scripts/` is where simple automation scripts go.
139-
- `test/` is where your tests should go.
137+
- `contracts/` where the source files for your contracts should be.
138+
- `scripts/` where simple automation scripts go.
139+
- `test/` where your tests should go.
140140
141-
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:
141+
We want to delete the default files inside the folders so we start afresh, i.e. we will create our own .sol file for our own contract, etc:
142142
143143
```bash
144144
rm contracts/*.sol
@@ -178,15 +178,15 @@ contract TierNFT {
178178
```
179179
180180
Now that we have our license, Solidity version and the
181-
contract defined, we can add the logic and the variables we need to store.
182-
183-
## What do we need?
184-
### we sort of need this 'intro' at the start of the lesson......
181+
contract defined, we can add the logic and the variables we need to store. As we are creating tiers for the categories of our NFTs, we need to also store information about tiers in our contracts. We'll write our smart contract step by step in five stages:
185182

186-
As we are creating tiers for the categories of our NFTs, we need to also store
187-
information about tiers in our contracts. We'll write our smart contract step by step in four stages.
183+
- add mint function
184+
- add tiers to utilise in mint function
185+
- create basic TokenURI function
186+
- enhance TokenURI function with SVG file
187+
- add withdraw function
188188

189-
### Inheriting OpenZeppelin ERC721 and adding a Mint Function
189+
### Add a Mint Function
190190

191191
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.
192192
@@ -229,9 +229,9 @@ contract TierNFT is ERC721 {
229229
230230
```
231231
232-
### Adding Tiers and Using Them in the Mint Function
232+
### Add Tiers
233233
234-
Next, to make our code neat and easily readable, just before the contract declaration add the tier Name and Value state variables, and assign their values, where each one represents a service subscription. Note that we assign the `constant` keyword, which is what it sounds like, meaning the values won't change, which also cuts down a lot on gas costs. Always good to know, but we'll go into 'gas optimisation' for you in a future lesson.
234+
Next, to make our code neat and easily readable, just before the contract declaration add the tier Name and Value state variables, and assign their values, where each one represents a service subscription. Note that we assign the `constant` keyword, which is what it sounds like, meaning the values won't change, which also cuts down a lot on gas costs. Always good to know, but we'll go into **gas optimisation** for you in a future lesson.
235235
236236
```solidity
237237
// SPDX-License-Identifier: MIT
@@ -264,9 +264,9 @@ contract TierNFT is ERC721 {
264264
}
265265
````
266266
267-
We have added `Basic`, `Medium` and `Premium` as tiers and assigned their values. We store the tier each NFT holds in `mapping(uint256 => uint256) public tokenTier;`. Mappings are widely used in Solidity, having many advantages. They are a great way to organise and access data efficiently, and therefore cheaply through 'key: value' pairs e.g. an address to a balance. We can also use nested mappings to allow for more complex data structures.
267+
We have added `Basic`, `Medium` and `Premium` as tiers and assigned their values. We store the tier each NFT holds in `mapping(uint256 => uint256) public tokenTier;`. Mappings are widely used in Solidity, having many advantages. They are a great way to organise and access data efficiently, and therefore cheaply through **key: value** pairs e.g. a balance **value** maps to an address **key**. We can also use nested mappings to allow for more complex data structures.
268268
269-
Now we need to modify the mint function with logic that can access the three NFT tiers separately. We use a 'conditional' `if/else if` statement to achieve this. If you've done any coding before now, you'll probably know `if`, and if so, you'll definitely know `if else`!
269+
Now we need to modify the mint function with logic that can access the three NFT tiers separately. We use a **conditional** `if/else if` statement to achieve this. If you've done any coding before now, you'll probably know `if`, and if so, you'll definitely know `if else`!
270270

271271
```solidity
272272
// state variables and contract definition...
@@ -297,9 +297,10 @@ Now we need to modify the mint function with logic that can access the three NFT
297297

298298
The mint function selects tiers based on the amount of native token it receives stored in `msg.value`.
299299

300-
The `require` statement is a simple and powerful built-in function of Solidity you'll be using a lot in the future. It checks if the 1st parameter is true or false. On true, it does nothing, allowing execution to continue normally, but on false it throws an exception that reverts everything we modified in the transaction. In our case, if we send the function zero token value, it will 'revert' with a "Not enough value for the minimum Tier" message, and stop executing. Otherwise we can select the tier we want..... as long as we can afford it!
300+
The `require` statement is a simple and powerful built-in function of Solidity you'll be using a lot in the future. It checks if the 1st parameter is true or false. On true, it does nothing, allowing execution to continue normally, but on false it throws an exception that reverts everything we modified in the transaction. In our case, if we send the function zero token value, it will **revert** with a "Not enough value for the minimum Tier" message, and stop executing. Otherwise we can select the tier we want..... as long as we can afford it!
301301

302-
We already have two `uint256` variables declared. You might wonder which one is which inside the `tokenTier` mapping? See if you can track through the code and find out - DEFO NEED A QUESTION OR TWO ON THIS - TO GET THAT ANSWER! AND ALSO TO CHECK ON STATE AND LOCAL VARIABLES e.g. `tierId` is declared with `0`.
302+
We already have two `uint256` variables declared. You might wonder which one is which inside the `tokenTier` mapping? See if you can track through the code and find out.
303+
{/* DEFO NEED A QUESTION OR TWO ON THIS - TO GET THAT ANSWER! AND ALSO TO CHECK ON STATE AND LOCAL VARIABLES e.g. `tierId` is declared with `0`. */}
303304

304305
<br/>
305306
<details>
@@ -346,7 +347,6 @@ contract TierNFT is ERC721 {
346347
</details>
347348
<br/>
348349
349-
CHECKPOINT QUESTIONS ⁉️ <br />
350350
<SideDrawer buttonText="Checkpoint Questions" title="Creating a Robust Development Environment">
351351
<Question question="lesson-3/<# of section block+section name/Q1" />
352352
<Question question="lesson-3//Q2" />
@@ -358,7 +358,7 @@ CHECKPOINT QUESTIONS ⁉️ <br />
358358
359359
PART 3
360360
361-
### Create a (simple) tokenURI function
361+
### Create tokenURI function
362362
363363
When we inherited Open Zeppelin's ERC721, it gave us a function for `tokenURI` where we can store an image, a video, or much more. With the help of this ERC721 contract we have the ability to define **a base path** for creating a
364364
unique URI which adds the token ID to the end of it.
@@ -373,7 +373,7 @@ Next, we import `Base64.sol` which encodes the tokenURI so it can return a JSON
373373
374374
Remember how we talked about this token ID at the end of the URI? `Strings.sol` will write it as a string inside the JSON file. Go ahead and import the magic of these two files to your contract.
375375
376-
For this lesson we won’t be creating a separate JSON file. We will actually code it into the contract.
376+
For this lesson we won’t be creating a separate JSON file. We will actually code it into the contract. Nifty, eh?
377377
378378
```solidity
379379
// mint function part of the code...
@@ -416,9 +416,9 @@ Let’s stop to break it down and examine it a little.
416416
function we'll use, since we are not creating a separate JSON file to store images or other services, but creating it right here in the contract.
417417
- We also added `require(_exists(tokenId). "Nonexistent token");` . According to ERC721 specification, it is required to throw an error if the NFT doesn't exist.
418418
- `imageSVG` is a placeholder for our image, and we will deal with it a bit later.
419-
- `Base64.encode` is for encoding the JSON into Base64 so browsers can translate
419+
- `Base64.encode` is for encoding the JSON into Base64, so browsers can translate
420420
it into a file much in the same way as a file attached to an email.
421-
- `string( abi.encodePacked () )` concatenates the string in a similar way to our previous lessons.
421+
- `string( abi.encodePacked () )` concatenates (joins together) the string in a similar way to in our *Getting Started...* lesson.
422422

423423
This is the JSON format of our metadata:
424424

@@ -515,9 +515,9 @@ uint256) public tokenTier;
515515
</details>
516516
<br/>
517517
518-
### Complete TokenURI function with our SVG
518+
### Complete TokenURI function with SVG
519519
520-
Okay. We've done a bunch of things with our contract and now we're going to do some scalable vector graphic magic!
520+
Okay. We've done a bunch of things with our contract, and now we're going to do some scalable vector graphic magic!
521521
522522
Add these lines right above the other constants defined for the tiers:
523523
@@ -527,8 +527,7 @@ string constant SVG_END = "</text></g></svg>";
527527
// string constant TIER_NAME = ...
528528
````
529529
530-
Here, we prepared the start and end of our SVG. We can test this out by joining
531-
the start and end of the SVG into this [online svg editor](https://editsvgcode.com/).
530+
Here, we prepared the start and end of our SVG. We can test this out by replacing the code in [online svg editor](https://editsvgcode.com/) with the start and end values we have provided above.
532531
533532
And now some more modifications. Inside the tokenURI function, right below `require(…)`, add these lines:
534533
@@ -654,7 +653,7 @@ contract TierNFT is ERC721 {
654653
</details>
655654
<br/>
656655
657-
### Where are all our funds??? We need a withdraw Function!
656+
### Where are all our funds? Add withdraw Function
658657
659658
We need to find a way to actually withdraw any funds our contract generates, otherwise they'll get stuck **in the contract** .... that we created!
660659

0 commit comments

Comments
 (0)