Skip to content

Commit 7ca8de0

Browse files
authored
Merge pull request #238 from Developer-DAO/lesson3-code-update
Lesson3 code update
2 parents b585224 + 5a7a87f commit 7ca8de0

File tree

2 files changed

+28
-21
lines changed
  • pages/lessons/projects
  • utils/questions/lesson-3/4-deploy-scripts

2 files changed

+28
-21
lines changed

pages/lessons/projects/3.mdx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Now that we have set the stage, it's time to dive into the exciting world of tie
5858
- Creating tiered NFTs with varying levels of rarity and attributes
5959
- Write scripts for deployment
6060
- Exploring additional functionalities and possibilities with tiered NFTs ... in the smart contract!
61-
- Showcasing and trading your tiered NFTs on a public marketplace
61+
- Securely manage sensitive environment variables
62+
- Showcasing your tiered NFTs on a public marketplace
6263

6364
### Developer tooling
6465

@@ -136,7 +137,7 @@ last prompt. If they didn’t install or we accidentally chose ‘n’, we can a
136137
install them manually with:
137138
138139
```bash
139-
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-chai-matchers
140+
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
140141
```
141142
</Callout>
142143
In a Hardhat project, some of the default folders are:
@@ -197,6 +198,9 @@ contract defined, we can add the logic and the variables we need to store. As we
197198

198199
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.
199200
201+
{/* @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. */}
202+
203+
200204
```solidity
201205
// SPDX-License-Identifier: MIT
202206
pragma solidity 0.8.12;
@@ -218,7 +222,7 @@ Now let’s go ahead and add a mint function which will call `_safeMint` from th
218222
// SPDX-License-Identifier: MIT
219223
pragma solidity 0.8.12;
220224
221-
import '@openzeppelin/contracts/token/ERC721/ERC721.sol'
225+
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
222226
223227
contract TierNFT is ERC721 {
224228
@@ -846,11 +850,11 @@ async function main() {
846850
COLLECTION_NAME,
847851
COLLECTION_SYMBOL,
848852
)
849-
await contract.deployed()
853+
854+
await contract.waitForDeployment()
850855
// Print our newly deployed contract address
851-
console.log(`Contract deployed to ${contract.address}`)
856+
console.log("Contract deployed at ", await contract.getAddress())
852857
}
853-
854858
/** Run Main function - Do not change **/
855859
main().catch((error) => {
856860
console.error(error)
@@ -862,13 +866,13 @@ main().catch((error) => {
862866
will tell Hardhat exactly **what** to deploy.
863867
- With `const COLLECTION_NAME = "TierNFT"` and
864868
`const COLLECTION_SYMBOL = "Tier"` - we define the *name* and *symbol* to pass to the constructor for the deployment.
865-
- `hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks Hardhat Runtime
866-
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.
869+
- `hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks `hre` (Hardhat Runtime
870+
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.
867871
- `contractFactory.deploy` - we are asking the contract factory to deploy an instance of our
868872
contract. This is the deploy transaction!
869873
- `COLLECTION_NAME, COLLECTION_SYMBOL` - these are the parameters for our
870874
contract's constructor function to set up its initial state.
871-
- `await contract.deployed()` - waits for the transaction to be approved by the network validators, and confirms that the deployment of the contract was successful, telling us that it's ready for use on the blockchain.
875+
- `await contract.waitForDeployment()` - waits for the transaction to be approved by the network validators, and confirms that the deployment of the contract was successful, telling us that it's ready for use on the blockchain.
872876
- Running the `main().catch( … )` script at the very end makes sure that all the previous
873877
code is executed, and also logs any errors, and prints them to the console.
874878

@@ -911,6 +915,8 @@ Note: **Always make sure to use a separate browser profile, with a separate wall
911915

912916
### Getting Some Testnet Funds
913917

918+
{/* @wolovim, maybe we should give a couple of testnet options, just in case. what do you think?*/}
919+
914920
A testnet is a sandbox environment where developers
915921
can test, create and modify functionalities, monitor and simulate a mainnet blockchain's network
916922
performance, fix bugs and other network failures without having to worry about breaking a main chain, and paying in real crypto coins to do so! Mainnets cost - testnets generally don't.
@@ -925,8 +931,7 @@ Note: Testnet and mainnet are separate networks. You can't for example send toke
925931
### Personal Security
926932
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**.
927933

928-
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
929-
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:
934+
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 *Show 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 warning to 'Never disclose this key'. Confirm and you'll be able to copy your private key. Add your private key into the `.env` file like so:
930935

931936
```bash
932937
PRIVATE_KEY=f8abc629b...
@@ -988,47 +993,49 @@ async function main() {
988993
const contractFactory = await hre.ethers.getContractFactory(CONTRACT_NAME)
989994
const contract = await contractFactory.attach(CONTRACT_ADDRESS)
990995
// Print our newly deployed contract address
991-
console.log(`Attached contract: ${contract.address}`)
996+
console.log("Attached contract ", await contract.getAddress())
992997

993998
// Call the mint function for Tier 0
994999
let txn = await contract.mint({
995-
value: hre.ethers.utils.parseEther(VALUE_TIER_0),
1000+
value: hre.ethers.parseEther(VALUE_TIER_0),
9961001
})
9971002
await txn.wait() // Wait for the NFT to be minted
9981003
console.log('Minted a Tier 0 NFT!')
9991004

10001005
// Call the mint function for Tier 1
10011006
txn = await contract.mint({
1002-
value: hre.ethers.utils.parseEther(VALUE_TIER_1),
1007+
value: hre.ethers.parseEther(VALUE_TIER_1),
10031008
})
10041009
await txn.wait() // Wait for the NFT to be minted
10051010
console.log('Minted a Tier 1 NFT!')
10061011

10071012
// Call the mint function for Tier 2
10081013
txn = await contract.mint({
1009-
value: hre.ethers.utils.parseEther(VALUE_TIER_2),
1010-
})
1014+
value: hre.ethers.parseEther(VALUE_TIER_2),
1015+
})
10111016
await txn.wait() // Wait for the NFT to be minted
10121017
console.log('Minted a Tier 2 NFT!')
10131018

1014-
let totalSupply = await contract.totalSupply()
1015-
console.log("Collection's new totalSupply: ", totalSupply)
1019+
// Print total number of minted NFTs
1020+
let totalSupply = await contract.totalSupply()
1021+
console.log("Collection's new totalSupply: ", totalSupply)
10161022
}
10171023

10181024
/** Run Main function - Do not change **/
10191025
main().catch((error) => {
10201026
console.error(error)
10211027
process.exitCode = 1
10221028
})
1029+
10231030
```
10241031

10251032
- `const contract = await contractFactory.attach(CONTRACT_ADDRESS)` will
10261033
make sure that we are not deploying the contract again. Instead we need
10271034
Hardhat to use the contract addresss we just deployed to the testnet.
10281035
- `let txn = await contract.mint(...` is calling the mint function.
1029-
- `value: hre.ethers.utils.parseEther(VALUE_TIER_0)` - defines the value that we
1036+
- `value: hre.ethers.parseEther(VALUE_TIER_0)` - defines the value that we
10301037
want to send to the mint function. This defines which *Tier* we get.
1031-
- `ethers.utils.parseEther` - here we use *Ethers* to translate the value into wei i.e. multiply it with 10\*\*18
1038+
- `ethers.parseEther` - here we use *Ethers* to translate the value into wei i.e. multiply it with 10\*\*18
10321039
- `let totalSupply = await contract.totalSupply()` - is calling the
10331040
`totalSupply()` function to check if the 3 NFTs minted correctly.
10341041
<br/>

utils/questions/lesson-3/4-deploy-scripts/Q2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"question": "What does the `await contract.deployed()` line do in the code?",
2+
"question": "What does the `await contract.waitForDeployment()` line do in the code?",
33
"options": [
44
{
55
"answer": " It deploys the contract to the blockchain."

0 commit comments

Comments
 (0)