@@ -97,7 +97,8 @@ following steps:
97
97
- Write scripts for deployment
98
98
- Exploring additional functionalities and possibilities with tiered NFTs ... in
99
99
the smart contract!
100
- - Showcasing and trading your tiered NFTs on a public marketplace
100
+ - Securely manage sensitive environment variables
101
+ - Showcasing your tiered NFTs on a public marketplace
101
102
102
103
### Developer tooling
103
104
@@ -179,7 +180,7 @@ last prompt. If they didn’t install or we accidentally chose ‘n’, we can a
179
180
install them manually with:
180
181
181
182
```bash
182
- npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-chai-matchers
183
+ npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
183
184
```
184
185
185
186
</Callout>
@@ -245,6 +246,8 @@ contracts. We'll write our smart contract step by step in five stages:
245
246
Let’s get started by inheriting OpenZeppelin' s ERC721.sol like we did last time.
246
247
We add a constructor to our contract, which will mirror the one from ERC721.sol.
247
248
249
+ {/* @wolovim optional line?: Unlike in our *Basic NFT* lesson, where we added a third parameter to the constructor for storing the token' s baseURI, we will have a different approach this time , which we will come to later. */ }
250
+
248
251
```solidity
249
252
// SPDX-License-Identifier: MIT
250
253
pragma solidity 0.8 .12 ;
@@ -267,7 +270,7 @@ remember what `++` does to our total supply?
267
270
// SPDX-License-Identifier: MIT
268
271
pragma solidity 0.8.12;
269
272
270
- import ' @openzeppelin / contracts/ token/ ERC721/ ERC721.sol '
273
+ import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
271
274
272
275
contract TierNFT is ERC721 {
273
276
@@ -939,11 +942,11 @@ async function main() {
939
942
COLLECTION_NAME,
940
943
COLLECTION_SYMBOL,
941
944
)
942
- await contract.deployed()
945
+
946
+ await contract.waitForDeployment()
943
947
// Print our newly deployed contract address
944
- console.log(` Contract deployed to ${ contract.address}` )
948
+ console.log(" Contract deployed at ", await contract.getAddress() )
945
949
}
946
-
947
950
/** Run Main function - Do not change **/
948
951
main().catch((error) => {
949
952
console.error(error)
@@ -956,17 +959,17 @@ main().catch((error) => {
956
959
- With `const COLLECTION_NAME = "TierNFT"` and
957
960
`const COLLECTION_SYMBOL = "Tier"` - we define the _name_ and _symbol_ to pass
958
961
to the constructor for the deployment.
959
- - `hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks Hardhat Runtime
960
- Environment to get us a contract factory for our contract specified by
961
- `CONTRACT_NAME`. A contract factory is a template that allows us to deploy
962
+ - `hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks `hre` (Hardhat
963
+ Runtime Environment) to get us a contract factory for our contract specified
964
+ by `CONTRACT_NAME`. A contract factory is a template that allows us to deploy
962
965
instances of that contract, which allows many advantages.
963
966
- `contractFactory.deploy` - we are asking the contract factory to deploy an
964
967
instance of our contract. This is the deploy transaction!
965
968
- `COLLECTION_NAME, COLLECTION_SYMBOL` - these are the parameters for our
966
969
contract's constructor function to set up its initial state.
967
- - `await contract.deployed ()` - waits for the transaction to be approved by the
968
- network validators, and confirms that the deployment of the contract was
969
- successful, telling us that it's ready for use on the blockchain.
970
+ - `await contract.waitForDeployment ()` - waits for the transaction to be
971
+ approved by the network validators, and confirms that the deployment of the
972
+ contract was successful, telling us that it's ready for use on the blockchain.
970
973
- Running the `main().catch( … )` script at the very end makes sure that all the
971
974
previous code is executed, and also logs any errors, and prints them to the
972
975
console.
@@ -1017,6 +1020,8 @@ seed phrases!**
1017
1020
1018
1021
### Getting Some Testnet Funds
1019
1022
1023
+ { /* @wolovim, maybe we should give a couple of testnet options, just in case. what do you think? */ }
1024
+
1020
1025
A testnet is a sandbox environment where developers can test, create and modify
1021
1026
functionalities, monitor and simulate a mainnet blockchain's network
1022
1027
performance, fix bugs and other network failures without having to worry about
@@ -1035,17 +1040,13 @@ can get tokens for multiple testnets.
1035
1040
1036
1041
### Personal Security
1037
1042
1038
- Take your time to understand the _ good practices_ in this section. Before we
1039
- deploy, we need to add a ` .env ` file to our root folder to make sure we are
1040
- ** not pushing and therefore exposing our private keys in public repositories** .
1041
-
1042
1043
For your wallet's private key, the most sensitive data of the project, you need
1043
1044
to open Metamask. Click on the three dots next to your _ Account Name_ , and then
1044
- on _ Account Details_ , click on _ Export Private Key_ . It will ask for your
1045
- Metamask password, the one you use to log in to your wallet each session, not
1046
- your seed phrase. It also shows you a notice so you know that you are entering
1047
- the _ danger zone _ . Confirm and you'll be able to copy your private key. Add your
1048
- private key into the ` .env ` file like so:
1045
+ on _ Account Details_ , click on _ Show Private Key_ . It will ask for your Metamask
1046
+ password, the one you use to log in to your wallet each session, not your seed
1047
+ phrase. It also shows you a warning to 'Never disclose this key'. Confirm and
1048
+ you'll be able to copy your private key. Add your private key into the ` .env `
1049
+ file like so:
1049
1050
1050
1051
``` bash
1051
1052
PRIVATE_KEY=f8abc629b...
@@ -1113,29 +1114,30 @@ async function main() {
1113
1114
const contractFactory = await hre .ethers .getContractFactory (CONTRACT_NAME );
1114
1115
const contract = await contractFactory .attach (CONTRACT_ADDRESS );
1115
1116
// Print our newly deployed contract address
1116
- console .log (` Attached contract: ${ contract .address } ` );
1117
+ console .log (" Attached contract " , await contract .getAddress () );
1117
1118
1118
1119
// Call the mint function for Tier 0
1119
1120
let txn = await contract .mint ({
1120
- value: hre .ethers .utils . parseEther (VALUE_TIER_0 ),
1121
+ value: hre .ethers .parseEther (VALUE_TIER_0 ),
1121
1122
});
1122
1123
await txn .wait (); // Wait for the NFT to be minted
1123
1124
console .log (" Minted a Tier 0 NFT!" );
1124
1125
1125
1126
// Call the mint function for Tier 1
1126
1127
txn = await contract .mint ({
1127
- value: hre .ethers .utils . parseEther (VALUE_TIER_1 ),
1128
+ value: hre .ethers .parseEther (VALUE_TIER_1 ),
1128
1129
});
1129
1130
await txn .wait (); // Wait for the NFT to be minted
1130
1131
console .log (" Minted a Tier 1 NFT!" );
1131
1132
1132
1133
// Call the mint function for Tier 2
1133
1134
txn = await contract .mint ({
1134
- value: hre .ethers .utils . parseEther (VALUE_TIER_2 ),
1135
+ value: hre .ethers .parseEther (VALUE_TIER_2 ),
1135
1136
});
1136
1137
await txn .wait (); // Wait for the NFT to be minted
1137
1138
console .log (" Minted a Tier 2 NFT!" );
1138
1139
1140
+ // Print total number of minted NFTs
1139
1141
let totalSupply = await contract .totalSupply ();
1140
1142
console .log (" Collection's new totalSupply: " , totalSupply);
1141
1143
}
@@ -1151,10 +1153,10 @@ main().catch((error) => {
1151
1153
sure that we are not deploying the contract again. Instead we need Hardhat to
1152
1154
use the contract addresss we just deployed to the testnet.
1153
1155
- ` let txn = await contract.mint(... ` is calling the mint function.
1154
- - ` value: hre.ethers.utils. parseEther(VALUE_TIER_0) ` - defines the value that we
1155
- want to send to the mint function. This defines which _ Tier_ we get.
1156
- - ` ethers.utils. parseEther ` - here we use _ Ethers_ to translate the value into
1157
- wei i.e. multiply it with 10\*\* 18
1156
+ - ` value: hre.ethers.parseEther(VALUE_TIER_0) ` - defines the value that we want
1157
+ to send to the mint function. This defines which _ Tier_ we get.
1158
+ - ` ethers.parseEther ` - here we use _ Ethers_ to translate the value into wei
1159
+ i.e. multiply it with 10\*\* 18
1158
1160
- ` let totalSupply = await contract.totalSupply() ` - is calling the
1159
1161
` totalSupply() ` function to check if the 3 NFTs minted correctly.
1160
1162
<br />
0 commit comments