You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/lessons/projects/3.mdx
+30-33Lines changed: 30 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ In the previous lesson, we talked about NFTs and their use cases. Unlike traditi
63
63
- an IDE
64
64
- optional decentralized storage accounts
65
65
- a web3 wallet for testing
66
-
- some test ETH
66
+
- some test MATIC
67
67
- an API key from an RPC provider.
68
68
69
69
We will guide you through each step, ensuring a fun and comprehensive learning experience. Let's get started on this exciting journey into the world of tiered NFTs, and unleash the endless possibilities they hold!
@@ -234,7 +234,7 @@ contract TierNFT is ERC721 {
234
234
235
235
### Add Tiers
236
236
237
-
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.
237
+
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.
238
238
239
239
```solidity
240
240
// SPDX-License-Identifier: MIT
@@ -302,8 +302,8 @@ The mint function selects tiers based on the amount of native token it receives
302
302
303
303
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!
304
304
305
-
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.
306
-
{/* 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`. */}
305
+
We already have two `uint256` variables declared. You might wonder which is the *key* and which the *value* inside the `tokenTier` mapping? See if you can track through the code and find out.
Next, we import `Base64.sol` which encodes the tokenURI so it can return a JSON file needed for the tier NFTs.
376
-
377
-
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.
375
+
Next, we import `Base64.sol` which encodes the tokenURI so it can return a JSON file needed for the tier NFTs. And how do we add 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.
378
376
379
-
For this lesson we won’t be creating a separate JSON file. We will actually code it into the contract. Nifty, eh?
377
+
For this lesson we won’t be creating a separate JSON file. We will actually code it into the contract! Nifty, eh?
380
378
381
379
```solidity
382
380
// mint function part of the code...
@@ -421,7 +419,7 @@ Let’s stop to break it down and examine it a little.
421
419
-`imageSVG` is a placeholder for our image, and we will deal with it a bit later.
422
420
-`Base64.encode` is for encoding the JSON into Base64, so browsers can translate
423
421
it into a file much in the same way as a file attached to an email.
424
-
-`string( abi.encodePacked () )` concatenates (joins together) the string in a similar way to in our *Getting Started...* lesson.
422
+
-`string( abi.encodePacked () )` concatenates the string.
425
423
426
424
This is the JSON format of our metadata:
427
425
@@ -432,7 +430,7 @@ This is the JSON format of our metadata:
432
430
'"}'
433
431
```
434
432
435
-
The part `data:image/svg+xml;base64` tells the browser that the code after the comma is a string of text written in Base64, so the browser
433
+
The `data:image/svg+xml;base64` part tells the browser that the code after the comma is a string of text written in Base64, so the browser
436
434
can decode it back into our SVG file format. For example, if our
437
435
collection `TierNFT`, and the TokenID were `3`, our JSON would end up look
-`tierName` will store the type of tierNFT we are getting.
551
+
-`tierName` will store the type of tierNFT we are getting. Its variable declaration with the series of `?` and `:` following it is a *ternary operator*, another type of *conditional* to check and assign the appropriate tier name based on the value of `tokenTier[tokenId]`. Is it *2*? Assign *TIER_NAME_2*, etc.
554
552
-`imageSVG` is to create an SVG image with the corresponding tier type inside it.
555
553
556
554
For marketplaces to recognize our NFT assets, we need to add some JSON attributes. We
@@ -850,7 +848,7 @@ main().catch((error) => {
850
848
- With `const COLLECTION_NAME = "TierNFT"` and
851
849
`const COLLECTION_SYMBOL = "Tier"` - we define the *name* and *symbol* to pass to the constructor for the deployment.
852
850
-`hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks Hardhat Runtime
853
-
Environment to get us a contract factory for our contract specified by `CONTRACT_NAME`. A contract factory is a template that allows us to deploy instances of that contract.
851
+
Environment to get us a contract factory for our contract specified by `CONTRACT_NAME`. A contract factory is a template that allows us to deploy instances of that contract, which allows many advantages.
854
852
-`contractFactory.deploy` - we are asking the contract factory to deploy an instance of our
855
853
contract. This is the deploy transaction!
856
854
-`COLLECTION_NAME, COLLECTION_SYMBOL` - these are the parameters for our
@@ -884,7 +882,7 @@ module.exports = {
884
882
885
883
886
884
887
-
Do you remember in *Build a Basic NFT* we looked at Ethereum RPC (remote procedure call) node providers? What we are doing is adding the RPC and network configuration to the config file. This will let you, as the deployer, connect **your** wallet to the testnet. Now we need to add some testnet tokens, so we can actually **pay** for the deployment of the contract!
885
+
Do you remember in *Build a Basic NFT* we looked at Ethereum RPC (remote procedure call) node providers? What we are doing is adding the RPC and network configuration to the *config file*. This will let you, as the deployer, connect **your** wallet to the testnet. Now we need to add some testnet tokens, so we can actually **pay** for the deployment of the contract!
888
886
889
887
### Adding the testnet network
890
888
@@ -906,16 +904,14 @@ performance, fix bugs and other network failures without having to worry about b
906
904
We get testnet tokens from faucets. A faucet is a website, which on request, will **drip** a small amount of testnet tokens onto your address, and sometimes require completion of small tasks before doing so.
907
905
some testnet on the wallets.
908
906
Note: Testnet and mainnet are separate networks. You can't for example send tokens from a testnet to a mainnet. Let's head over and get some on this
909
-
[website](https://faucet.paradigm.xyz/).
907
+
[website](https://faucet.paradigm.xyz/). If you complete the required tasks, you can get tokens for multiple testnets.
910
908
911
909

912
910
913
-
If you complete the required tasks, you can get tokens for multiple testnets.
914
-
911
+
### Personal Security
912
+
Take your time to understand the *good practices* in this section. Before we deploy, we need to add a `.env` file to our root folder to make sure we are **not pushing and therefore exposing our private keys in public repositories**.
915
913
916
-
Before we deploy, we need to add a `.env` file to our root folder to make sure we are **not pushing and therefore exposing our private keys in public repositories**.
917
-
918
-
For your wallet's private key, the most sensitive data of the project, you need to open Metamask. Click on the three dots next to your Account Name, and then on Account Details, click on Export Private Key. It will ask for your Metamask password, the one you use to log in to your wallet each session, not your seed phrase. It also shows you a
914
+
For your wallet's private key, the most sensitive data of the project, you need to open Metamask. Click on the three dots next to your *Account Name*, and then on *Account Details*, click on *Export Private Key*. It will ask for your Metamask password, the one you use to log in to your wallet each session, not your seed phrase. It also shows you a
919
915
notice so you know that you are entering the *danger zone*. Confirm and you'll be able to copy your private key. Add your private key into the `.env` file like so:
920
916
921
917
```bash
@@ -939,9 +935,9 @@ This takes care of loading our environment variables from the `.env` file, so we
939
935
don’t have to store sensitive information, such as private keys, to standard
940
936
configuration files, which may need uploaded to a project's repo.
941
937
942
-
Remember to always **protect your private keys, and your recovery seed phrases** to keep your wallet safe and unwanted guests out.
938
+
Remember to always **protect your private keys, and your recovery seed phrases** to keep your wallet safe and **unwanted guests out**.
943
939
944
-
### It’s Time
940
+
### It’s Time . . . .
945
941
946
942
We will deploy our smart contract by using this command:
947
943
@@ -953,7 +949,7 @@ We specify the network where we want the contract to be deployed using the --net
953
949
954
950

955
951
956
-
**Woohoo!** Finally we deployed our contract! And a contract address, which we will need in a bit.
952
+
**Woohoo!** Finally we deployed our contract! And got a contract address, which we will need in a bit.
957
953
958
954
### Create a Script to Mint our tier NFTs
959
955
@@ -1017,12 +1013,12 @@ main().catch((error) => {
1017
1013
Hardhat to use the contract addresss we just deployed to the testnet.
1018
1014
-`let txn = await contract.mint(...` is calling the mint function.
1019
1015
-`value: hre.ethers.utils.parseEther(VALUE_TIER_0)` - defines the value that we
1020
-
want to send to the mint function. This defines which Tier we get.
1021
-
-`ethers.utils.parseEther` - here we use Ethers to translate the value into wei i.e. multiply it with 10\*\*18
1016
+
want to send to the mint function. This defines which *Tier* we get.
1017
+
-`ethers.utils.parseEther` - here we use *Ethers* to translate the value into wei i.e. multiply it with 10\*\*18
1022
1018
-`let totalSupply = await contract.totalSupply()` - is calling the
1023
1019
`totalSupply()` function to check if the 3 NFTs minted correctly.
1024
1020
1025
-
### Let’s MINT
1021
+
### Let’s mint!
1026
1022
1027
1023
To mint our tier NFTs we will run the following command.
1028
1024
@@ -1036,26 +1032,27 @@ If we look at our terminal we will see something like this.
1036
1032
1037
1033
You have just minted 3 NFTs - with different Tiers!
1038
1034
1039
-
Let’s go ahead and view them on the Opensea marketplace. This could take a few
1040
-
minutes to appear, don't panic. You can search in
1035
+
Let’s go ahead and view them on the Opensea marketplace. They could take a few
1036
+
minutes to appear, no need to panic 😎 You can search in
1041
1037
[https://testnets.opensea.io/](https://testnets.opensea.io/) for your newly created collection
1042
1038
with your contract address, or with the name that you chose.
0 commit comments