Skip to content

Commit b585224

Browse files
authored
Merge pull request #236 from Developer-DAO/lesson2-upgrade-code
undefined
2 parents a6e7b5a + 45ac2e1 commit b585224

File tree

2 files changed

+45
-45
lines changed
  • pages/lessons/projects
  • utils/questions/lesson-2/4-nft-id

2 files changed

+45
-45
lines changed

pages/lessons/projects/2.mdx

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ assets.
9090
Now that we know they can be much more than just an image, what are we waiting
9191
for?
9292

93-
**By the end of this lesson we'll have learned a lot.** A breakdown of the steps
93+
## Lesson breakdown
94+
95+
By the end of this lesson we'll have learned a lot. A breakdown of the steps
9496
to get there is:
9597

9698
- set up our development environment
@@ -104,7 +106,9 @@ to get there is:
104106
- _mint_, i.e. create our very own NFT
105107
- see our NFT in a public marketplace
106108

107-
**To achieve this, we'll need diverse developer tools.** We'll also need to open
109+
## Dev tools
110+
111+
To achieve this, we'll need diverse developer tools. We'll also need to open
108112
a couple of accounts as we progress from one development environment to the
109113
next. We'll be using:
110114

@@ -235,7 +239,7 @@ last prompt. If they didn’t install or we accidentally chose ‘n’, we can a
235239
install them manually with:
236240

237241
```bash
238-
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-chai-matchers
242+
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
239243
```
240244

241245
</Callout>
@@ -261,7 +265,7 @@ rm scripts/*.js
261265
rm test/*.js
262266
```
263267

264-
We now need to add our last dependency (OpenZeppelin contracts):
268+
We now need to add our last dependency - OpenZeppelin contracts:
265269

266270
```bash
267271
npm install @openzeppelin/contracts
@@ -318,8 +322,8 @@ contract ProjectNFT {
318322

319323
If you’ve been through our [first project](/lessons/projects/1), you’ll remember
320324
the first lines defines our copyright license, the second one defines the
321-
solidity version we are going to be using for this contract and the last two
322-
lines are how we declare a smart contract in solidity.
325+
Solidity version we are going to be using for this contract and the last two
326+
lines are how we declare a smart contract in Solidity.
323327

324328
With an empty project, we can now start adding what we need to create our
325329
awesome NFT collection. ERC721, the formal specification to follow for NFTs, has
@@ -400,7 +404,7 @@ contract ProjectNFT is ERC721 {
400404
}
401405
```
402406

403-
We made our totalSupply variable private and it will store the exact number of
407+
We made our `totalSupply` variable `private` and it will store the exact number of
404408
NFTs that have been minted. In the next step we will use this variable to
405409
identify each new NFT that’s created.
406410

@@ -474,7 +478,7 @@ Identifier), a web address if you prefer, that points to something on the
474478
internet, whatever we want it to be. e.g. a video, an image.
475479

476480
OpenZeppelin ERC721 contract provides us a way to create unique URIs from the
477-
IDs of the NFTs. It gives a way to define a base path for a web address and just
481+
IDs of the NFTs. It gives a way to define a 'base path' for a web address and just
478482
attaches the token ID at the end of it. So, if you wanted, you could upload your
479483
NFT info (we'll look at how we store that later) to any web address, say
480484
`www.my-site.com/my-nft-collection` and number each file with the corresponding
@@ -673,7 +677,7 @@ To achieve this, you need to add the json files all at the same time, as a
673677
**folder** into Pinata, and then you get a CID for the folder, which you can
674678
reference with the filenames at the end for each file.
675679

676-
Remember `_baseURI` function in our solidity contract? The one that was used to
680+
Remember `_baseURI` function in our Solidity contract? The one that was used to
677681
create the NFT tokenURI? There's where we are going to get the Pinata link with
678682
the CID to our folder.
679683

@@ -737,7 +741,7 @@ const hre = require('hardhat')
737741
const CONTRACT_NAME = 'ProjectNFT'
738742

739743
// The 3 parameters for our smart contract's constructor (CHANGE THESE to your own NFT name and description)
740-
const NFT_NAME = 'Academy'
744+
const NFT_NAME = 'D_D Academy'
741745
const NFT_DESCRIPTION = 'D_D Academy Basic NFT Collection'
742746

743747
// CHANGE THIS if you created your own images/JSONs:
@@ -757,10 +761,10 @@ async function main() {
757761
)
758762

759763
// We wait for it to be deployed to the blockchain
760-
await contract.deployed()
764+
await contract.waitForDeployment()
761765

762766
// We print the contract's address to the console
763-
console.log(`${CONTRACT_NAME} deployed to: ${contract.address}`)
767+
console.log(`${CONTRACT_NAME} deployed to: `, await contract.getAddress())
764768

765769
// --> ( We'll add more stuff here later ) <--
766770
}
@@ -772,6 +776,7 @@ main()
772776
console.error(error)
773777
process.exit(1)
774778
})
779+
775780
```
776781

777782
The code has comments outlining what each section does, but it basically has 1
@@ -781,13 +786,13 @@ and a Base URI for our files. With that info set at the top, the script deploys
781786
the contract, waits for it to be deployed and then prints the address of our
782787
deployed contract to the console.
783788

784-
Before we run our script, we need to tell Hardhat what solidity version our
789+
Before we run our script, we need to tell Hardhat what Solidity version our
785790
contracts are using. For that, we need to go into the `hardhat.config.js` file
786-
in our root folder. Find the line that says `solidity: '0.8.xx',` and replace
791+
in our project's root folder. Find the line that says `solidity: '0.8.xx',` and replace
787792
the `0.8.xx` for the pragma used in our contract: `0.8.12`.
788793

789-
We could have used a range of solidity versions e.g. `^0.8.0` in our contract,
790-
but we like to promote best practices by choosing a fixed solidity version and
794+
We could have used a range of Solidity versions e.g. `^0.8.0` in our contract,
795+
but we like to promote best practices by choosing a fixed Solidity version and
791796
knowing beforehand nothing is going to change in our bytecode if a new version
792797
in that range is released.
793798

@@ -863,30 +868,25 @@ going to run the deploy again, but this time to a testnet.
863868
What is a testnet? It is a basically a whole running blockchain, but it runs
864869
only so people can try stuff out. On it, you have ETH, NFTs, or other tokens but
865870
they have no monetary value. This way, you can develop and test your contracts
866-
without fear of losing anything valuable. For the moment, we are choosing to do
867-
this on \*Goerli\*\* testnet. It's one of the many of Ethereum testnets.
868-
869-
- We had wanted to use the Sepolia testnet, because Goerli is going to be
870-
deprecated by the end of 2023, but we're temporarily restricted, because there
871-
isn't yet a compatible NFT test hosting site for Sepolia. We will update the
872-
lesson accordingly when this availability arrives.
871+
without fear of losing anything valuable. Ethereum has many testnets, and you might
872+
notice that we used *Goerli* testnet. But we suggest that you use *Sepolia* testnet,
873+
now that it has compatible NFT hosting support, and longevity for app development that *Goerli* won't outlast.
873874

874875
Before we go any further, let's take an extra step for precaution. In the next
875876
project we'll learn how to use collaborative tools to store our projects, but
876-
for now, let's open our root directory's `.gitignore` file an add this line
877-
anywhere:
877+
for now, let's open our root directory's `.gitignore` file and add this line:
878878

879879
```bash
880880
hardhat.config.js
881881
```
882882

883883
In order to deploy to a real testnet we'll need:
884884

885-
- An Ethereum wallet that can connect to Goerli [Metamask](https://metamask.io/)
885+
- An Ethereum wallet that can connect to Sepolia. [Metamask](https://metamask.io/)
886886
is often used
887-
- Some Goerli-ETH. You can ask for some in a faucet, it's free, although some
888-
are faster than others! Options: [#1](https://goerlifaucet.com/),
889-
[#2](https://faucets.chain.link/goerli), [#3](https://faucet.paradigm.xyz/)
887+
- Some Sepolia-ETH. You can ask for some in a faucet, it's free, although some
888+
are faster than others! Options: [#1](https://sepoliafaucet.com/),
889+
[#2](https://testnet-faucet.com/sepolia/), [#3](https://faucet.quicknode.com/ethereum/sepolia)
890890
- An API Key from an Ethereum RPC Node Provider
891891
([Alchemy](https://www.alchemy.com/), [Infura](https://infura.io/),
892892
[Ankr](https://rpc.ankr.com/eth_goerli))
@@ -917,9 +917,9 @@ one of the Ethereum RPC Node Providers. Alchemy and Infura are the most used.
917917
And Ankr has a 'community endpoint' which doesn't require a dedicated sign up,
918918
to list a few options.
919919

920-
After signing up, you'll be asked to create an App. Be sure to select the Goerli
920+
After signing up, you'll be asked to create an App. Be sure to select the Sepolia
921921
network there. When the app is created, you'll see a 'View Key' button, or
922-
similar. Press it and copy the HTTP link, we'll use it in our next step.
922+
similar. Press it and copy the HTTP link, we'll use it as the API-KEY in our next step.
923923

924924
With our wallet funded fake ETH, we can go ahead and change our Hardhat
925925
configuration file. Go into your project's main directory and open
@@ -928,8 +928,7 @@ configuration file. Go into your project's main directory and open
928928
We are going to replace our file with this:
929929

930930
```jsx
931-
require('@nomicfoundation/hardhat-chai-matchers')
932-
require('@nomiclabs/hardhat-ethers')
931+
require("@nomicfoundation/hardhat-toolbox")
933932

934933
const WALLET_PRIVATE_KEY = 'YOUR-PRIVATE-KEY-DONT-SHARE'
935934

@@ -949,19 +948,19 @@ module.exports = {
949948
}
950949
```
951950

952-
And you need to fill those 2 global variables with your own for hardhat to
953-
communicate correctly to the network.
951+
And you'll need to set the two global variables using the `const` keyword with your own values
952+
for Hardhat to communicate correctly to the network.
954953

955954
We have already gone through how to get your API KEY.
956955

957956
For your wallet's private key, the most sensitive data of the project, you need
958-
to open Metamask, click on the three dots next to your Account Name, and then on
959-
Account Details, then click on Export Private Key. It will ask for your Metamask
960-
password (the one you use to open it, NOT your seed phrase). It also shows you a
961-
notice so you know that you are entering the danger zone. Confirm and you'll be
962-
able to copy your private key. Paste it in to our `hardhat.config.js`
957+
to open Metamask, click on the three dots next to your *Account Name*, and then on
958+
*Account Details*, then click on *Export Private Key*. It will ask for your Metamask
959+
password - the one you use to open it, NOT your seed phrase. It also issues a warning to
960+
'Never disclose this key'. Confirm and you'll be able to copy your private key. Paste
961+
it in to our `hardhat.config.js`
963962

964-
Please, if you are already a developer and you plan to use Git to store your
963+
Please, if you are already a developer, and you plan to use Git to store your
965964
project, don't store your `hardhat.config.js` on it, because you will have your
966965
private key there.
967966

@@ -977,7 +976,7 @@ private key there.
977976
</SideDrawer>
978977
<br />
979978

980-
Ok. We are ready, let's deploy to the Goerli testnet!
979+
Ok. We are ready, let's deploy to the Sepolia testnet!
981980

982981
Now we need to run our deploy.js script and the deployment is going to cost us
983982
some ETH - test ETH, don't worry - from our wallet, since we are storing
@@ -989,7 +988,7 @@ deploy, delete all the lines we added to test the minting.
989988
Run:
990989

991990
```bash
992-
npx hardhat run scripts/deploy.js --network goerli
991+
npx hardhat run scripts/deploy.js --network sepolia
993992
```
994993

995994
This is the output i got in my console:
@@ -1005,7 +1004,7 @@ next project we will learn about tools to collaborate and store your projects
10051004
online.
10061005

10071006
So now we can go and explore the chain to find your contract (and mine too!).
1008-
Just go to [Goerli Etherscan](https://goerli.etherscan.io/) (or
1007+
Just go to [Sepolia Etherscan](https://sepolia.etherscan.io/) (or
10091008
[Opensea](https://testnets.opensea.io/)) and search for the address of our
10101009
deployed contract.
10111010

utils/questions/lesson-2/4-nft-id/Q5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"answer": "Because it looks more professional"
66
},
77
{
8-
"answer": "Because you need to keep your personal assets separate from your development funds"
8+
"answer": "Because you need to keep your personal assets separate from your development funds",
9+
"correct": true
910
},
1011
{
1112
"answer": "Every milisecond counts for a dev, and separate wallets are faster to connect to the blockchain"

0 commit comments

Comments
 (0)