@@ -90,7 +90,9 @@ assets.
90
90
Now that we know they can be much more than just an image, what are we waiting
91
91
for?
92
92
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
94
96
to get there is:
95
97
96
98
- set up our development environment
@@ -104,7 +106,9 @@ to get there is:
104
106
- _ mint_ , i.e. create our very own NFT
105
107
- see our NFT in a public marketplace
106
108
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
108
112
a couple of accounts as we progress from one development environment to the
109
113
next. We'll be using:
110
114
@@ -235,7 +239,7 @@ last prompt. If they didn’t install or we accidentally chose ‘n’, we can a
235
239
install them manually with:
236
240
237
241
```bash
238
- npm install --save-dev hardhat @nomicfoundation / hardhat- toolbox @nomicfoundation / hardhat - chai - matchers
242
+ npm install --save-dev hardhat @nomicfoundation / hardhat- toolbox
239
243
```
240
244
241
245
</Callout >
@@ -261,7 +265,7 @@ rm scripts/*.js
261
265
rm test/* .js
262
266
```
263
267
264
- We now need to add our last dependency ( OpenZeppelin contracts) :
268
+ We now need to add our last dependency - OpenZeppelin contracts:
265
269
266
270
``` bash
267
271
npm install @openzeppelin/contracts
@@ -318,8 +322,8 @@ contract ProjectNFT {
318
322
319
323
If you’ve been through our [ first project] ( /lessons/projects/1 ) , you’ll remember
320
324
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 .
323
327
324
328
With an empty project, we can now start adding what we need to create our
325
329
awesome NFT collection. ERC721, the formal specification to follow for NFTs, has
@@ -400,7 +404,7 @@ contract ProjectNFT is ERC721 {
400
404
}
401
405
```
402
406
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
404
408
NFTs that have been minted. In the next step we will use this variable to
405
409
identify each new NFT that’s created.
406
410
@@ -474,7 +478,7 @@ Identifier), a web address if you prefer, that points to something on the
474
478
internet, whatever we want it to be. e.g. a video, an image.
475
479
476
480
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
478
482
attaches the token ID at the end of it. So, if you wanted, you could upload your
479
483
NFT info (we'll look at how we store that later) to any web address, say
480
484
` 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
673
677
** folder** into Pinata, and then you get a CID for the folder, which you can
674
678
reference with the filenames at the end for each file.
675
679
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
677
681
create the NFT tokenURI? There's where we are going to get the Pinata link with
678
682
the CID to our folder.
679
683
@@ -737,7 +741,7 @@ const hre = require('hardhat')
737
741
const CONTRACT_NAME = ' ProjectNFT'
738
742
739
743
// 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'
741
745
const NFT_DESCRIPTION = ' D_D Academy Basic NFT Collection'
742
746
743
747
// CHANGE THIS if you created your own images/JSONs:
@@ -757,10 +761,10 @@ async function main() {
757
761
)
758
762
759
763
// We wait for it to be deployed to the blockchain
760
- await contract .deployed ()
764
+ await contract .waitForDeployment ()
761
765
762
766
// 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 () )
764
768
765
769
// --> ( We'll add more stuff here later ) <--
766
770
}
@@ -772,6 +776,7 @@ main()
772
776
console .error (error)
773
777
process .exit (1 )
774
778
})
779
+
775
780
```
776
781
777
782
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
781
786
the contract, waits for it to be deployed and then prints the address of our
782
787
deployed contract to the console.
783
788
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
785
790
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
787
792
the ` 0.8.xx ` for the pragma used in our contract: ` 0.8.12 ` .
788
793
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
791
796
knowing beforehand nothing is going to change in our bytecode if a new version
792
797
in that range is released.
793
798
@@ -863,30 +868,25 @@ going to run the deploy again, but this time to a testnet.
863
868
What is a testnet? It is a basically a whole running blockchain, but it runs
864
869
only so people can try stuff out. On it, you have ETH, NFTs, or other tokens but
865
870
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.
873
874
874
875
Before we go any further, let's take an extra step for precaution. In the next
875
876
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:
878
878
879
879
``` bash
880
880
hardhat.config.js
881
881
```
882
882
883
883
In order to deploy to a real testnet we'll need:
884
884
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/ )
886
886
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 )
890
890
- An API Key from an Ethereum RPC Node Provider
891
891
([ Alchemy] ( https://www.alchemy.com/ ) , [ Infura] ( https://infura.io/ ) ,
892
892
[ 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.
917
917
And Ankr has a 'community endpoint' which doesn't require a dedicated sign up,
918
918
to list a few options.
919
919
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
921
921
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.
923
923
924
924
With our wallet funded fake ETH, we can go ahead and change our Hardhat
925
925
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
928
928
We are going to replace our file with this:
929
929
930
930
``` jsx
931
- require (' @nomicfoundation/hardhat-chai-matchers' )
932
- require (' @nomiclabs/hardhat-ethers' )
931
+ require (" @nomicfoundation/hardhat-toolbox" )
933
932
934
933
const WALLET_PRIVATE_KEY = ' YOUR-PRIVATE-KEY-DONT-SHARE'
935
934
@@ -949,19 +948,19 @@ module.exports = {
949
948
}
950
949
```
951
950
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.
954
953
955
954
We have already gone through how to get your API KEY.
956
955
957
956
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 `
963
962
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
965
964
project, don't store your ` hardhat.config.js ` on it, because you will have your
966
965
private key there.
967
966
@@ -977,7 +976,7 @@ private key there.
977
976
</SideDrawer >
978
977
<br />
979
978
980
- Ok. We are ready, let's deploy to the Goerli testnet!
979
+ Ok. We are ready, let's deploy to the Sepolia testnet!
981
980
982
981
Now we need to run our deploy.js script and the deployment is going to cost us
983
982
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.
989
988
Run:
990
989
991
990
``` bash
992
- npx hardhat run scripts/deploy.js --network goerli
991
+ npx hardhat run scripts/deploy.js --network sepolia
993
992
```
994
993
995
994
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
1005
1004
online.
1006
1005
1007
1006
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
1009
1008
[ Opensea] ( https://testnets.opensea.io/ ) ) and search for the address of our
1010
1009
deployed contract.
1011
1010
0 commit comments