@@ -95,8 +95,10 @@ assets.
95
95
Now that we know they can be much more than just an image, what are we waiting
96
96
for?
97
97
98
- ** By the end of this lesson we'll have learned a lot.** A breakdown of the steps
99
- to get there is:
98
+ ## Lesson breakdown
99
+
100
+ By the end of this lesson we'll have learned a lot. A breakdown of the steps to
101
+ get there is:
100
102
101
103
- set up our development environment
102
104
- install dependencies
@@ -109,9 +111,11 @@ to get there is:
109
111
- _ mint_ , i.e. create our very own NFT
110
112
- see our NFT in a public marketplace
111
113
112
- ** To achieve this, we'll need diverse developer tools.** We'll also need to open
113
- a couple of accounts as we progress from one development environment to the
114
- next. We'll be using:
114
+ ## Dev tools
115
+
116
+ To achieve this, we'll need diverse developer tools. We'll also need to open a
117
+ couple of accounts as we progress from one development environment to the next.
118
+ We'll be using:
115
119
116
120
- a console
117
121
- an IDE
@@ -240,7 +244,7 @@ last prompt. If they didn’t install or we accidentally chose ‘n’, we can a
240
244
install them manually with:
241
245
242
246
```bash
243
- npm install --save-dev hardhat @nomicfoundation / hardhat- toolbox @nomicfoundation / hardhat - chai - matchers
247
+ npm install --save-dev hardhat @nomicfoundation / hardhat- toolbox
244
248
```
245
249
246
250
</Callout >
@@ -266,7 +270,7 @@ rm scripts/*.js
266
270
rm test/* .js
267
271
```
268
272
269
- We now need to add our last dependency ( OpenZeppelin contracts) :
273
+ We now need to add our last dependency - OpenZeppelin contracts:
270
274
271
275
``` bash
272
276
npm install @openzeppelin/contracts
@@ -323,8 +327,8 @@ contract ProjectNFT {
323
327
324
328
If you’ve been through our [ first project] ( /lessons/projects/1 ) , you’ll remember
325
329
the first lines defines our copyright license, the second one defines the
326
- solidity version we are going to be using for this contract and the last two
327
- lines are how we declare a smart contract in solidity .
330
+ Solidity version we are going to be using for this contract and the last two
331
+ lines are how we declare a smart contract in Solidity .
328
332
329
333
With an empty project, we can now start adding what we need to create our
330
334
awesome NFT collection. ERC721, the formal specification to follow for NFTs, has
@@ -405,8 +409,8 @@ contract ProjectNFT is ERC721 {
405
409
}
406
410
```
407
411
408
- We made our totalSupply variable private and it will store the exact number of
409
- NFTs that have been minted. In the next step we will use this variable to
412
+ We made our ` totalSupply ` variable ` private ` and it will store the exact number
413
+ of NFTs that have been minted. In the next step we will use this variable to
410
414
identify each new NFT that’s created.
411
415
412
416
<SideDrawer
@@ -479,9 +483,9 @@ Identifier), a web address if you prefer, that points to something on the
479
483
internet, whatever we want it to be. e.g. a video, an image.
480
484
481
485
OpenZeppelin ERC721 contract provides us a way to create unique URIs from the
482
- IDs of the NFTs. It gives a way to define a base path for a web address and just
483
- attaches the token ID at the end of it. So, if you wanted, you could upload your
484
- NFT info (we'll look at how we store that later) to any web address, say
486
+ IDs of the NFTs. It gives a way to define a ' base path' for a web address and
487
+ just attaches the token ID at the end of it. So, if you wanted, you could upload
488
+ your NFT info (we'll look at how we store that later) to any web address, say
485
489
` www.my-site.com/my-nft-collection ` and number each file with the corresponding
486
490
ID (1, 2, 3, 4…).
487
491
@@ -678,7 +682,7 @@ To achieve this, you need to add the json files all at the same time, as a
678
682
** folder** into Pinata, and then you get a CID for the folder, which you can
679
683
reference with the filenames at the end for each file.
680
684
681
- Remember ` _baseURI ` function in our solidity contract? The one that was used to
685
+ Remember ` _baseURI ` function in our Solidity contract? The one that was used to
682
686
create the NFT tokenURI? There's where we are going to get the Pinata link with
683
687
the CID to our folder.
684
688
@@ -742,7 +746,7 @@ const hre = require("hardhat");
742
746
const CONTRACT_NAME = " ProjectNFT" ;
743
747
744
748
// The 3 parameters for our smart contract's constructor (CHANGE THESE to your own NFT name and description)
745
- const NFT_NAME = " Academy" ;
749
+ const NFT_NAME = " D_D Academy" ;
746
750
const NFT_DESCRIPTION = " D_D Academy Basic NFT Collection" ;
747
751
748
752
// CHANGE THIS if you created your own images/JSONs:
@@ -762,10 +766,10 @@ async function main() {
762
766
);
763
767
764
768
// We wait for it to be deployed to the blockchain
765
- await contract .deployed ();
769
+ await contract .waitForDeployment ();
766
770
767
771
// We print the contract's address to the console
768
- console .log (` ${ CONTRACT_NAME } deployed to: ${ contract .address } ` );
772
+ console .log (` ${ CONTRACT_NAME } deployed to: ` , await contract .getAddress () );
769
773
770
774
// --> ( We'll add more stuff here later ) <--
771
775
}
@@ -786,13 +790,13 @@ and a Base URI for our files. With that info set at the top, the script deploys
786
790
the contract, waits for it to be deployed and then prints the address of our
787
791
deployed contract to the console.
788
792
789
- Before we run our script, we need to tell Hardhat what solidity version our
793
+ Before we run our script, we need to tell Hardhat what Solidity version our
790
794
contracts are using. For that, we need to go into the ` hardhat.config.js ` file
791
- in our root folder. Find the line that says ` solidity: '0.8.xx', ` and replace
792
- the ` 0.8.xx ` for the pragma used in our contract: ` 0.8.12 ` .
795
+ in our project's root folder. Find the line that says ` solidity: '0.8.xx', ` and
796
+ replace the ` 0.8.xx ` for the pragma used in our contract: ` 0.8.12 ` .
793
797
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
798
+ We could have used a range of Solidity versions e.g. ` ^0.8.0 ` in our contract,
799
+ but we like to promote best practices by choosing a fixed Solidity version and
796
800
knowing beforehand nothing is going to change in our bytecode if a new version
797
801
in that range is released.
798
802
@@ -868,30 +872,27 @@ going to run the deploy again, but this time to a testnet.
868
872
What is a testnet? It is a basically a whole running blockchain, but it runs
869
873
only so people can try stuff out. On it, you have ETH, NFTs, or other tokens but
870
874
they have no monetary value. This way, you can develop and test your contracts
871
- without fear of losing anything valuable. For the moment, we are choosing to do
872
- this on \* Goerli\*\* testnet. It's one of the many of Ethereum testnets.
873
-
874
- - We had wanted to use the Sepolia testnet, because Goerli is going to be
875
- deprecated by the end of 2023, but we're temporarily restricted, because there
876
- isn't yet a compatible NFT test hosting site for Sepolia. We will update the
877
- lesson accordingly when this availability arrives.
875
+ without fear of losing anything valuable. Ethereum has many testnets, and you
876
+ might notice that we used _ Goerli_ testnet. But we suggest that you use
877
+ _ Sepolia_ testnet, now that it has compatible NFT hosting support, and longevity
878
+ for app development that _ Goerli_ won't outlast.
878
879
879
880
Before we go any further, let's take an extra step for precaution. In the next
880
881
project we'll learn how to use collaborative tools to store our projects, but
881
- for now, let's open our root directory's ` .gitignore ` file an add this line
882
- anywhere:
882
+ for now, let's open our root directory's ` .gitignore ` file and add this line:
883
883
884
884
``` bash
885
885
hardhat.config.js
886
886
```
887
887
888
888
In order to deploy to a real testnet we'll need:
889
889
890
- - An Ethereum wallet that can connect to Goerli [ Metamask] ( https://metamask.io/ )
891
- is often used
892
- - Some Goerli-ETH. You can ask for some in a faucet, it's free, although some
893
- are faster than others! Options: [ #1 ] ( https://goerlifaucet.com/ ) ,
894
- [ #2 ] ( https://faucets.chain.link/goerli ) , [ #3 ] ( https://faucet.paradigm.xyz/ )
890
+ - An Ethereum wallet that can connect to Sepolia.
891
+ [ Metamask] ( https://metamask.io/ ) is often used
892
+ - Some Sepolia-ETH. You can ask for some in a faucet, it's free, although some
893
+ are faster than others! Options: [ #1 ] ( https://sepoliafaucet.com/ ) ,
894
+ [ #2 ] ( https://testnet-faucet.com/sepolia/ ) ,
895
+ [ #3 ] ( https://faucet.quicknode.com/ethereum/sepolia )
895
896
- An API Key from an Ethereum RPC Node Provider
896
897
([ Alchemy] ( https://www.alchemy.com/ ) , [ Infura] ( https://infura.io/ ) ,
897
898
[ Ankr] ( https://rpc.ankr.com/eth_goerli ) )
@@ -922,9 +923,10 @@ one of the Ethereum RPC Node Providers. Alchemy and Infura are the most used.
922
923
And Ankr has a 'community endpoint' which doesn't require a dedicated sign up,
923
924
to list a few options.
924
925
925
- After signing up, you'll be asked to create an App. Be sure to select the Goerli
926
- network there. When the app is created, you'll see a 'View Key' button, or
927
- similar. Press it and copy the HTTP link, we'll use it in our next step.
926
+ After signing up, you'll be asked to create an App. Be sure to select the
927
+ Sepolia network there. When the app is created, you'll see a 'View Key' button,
928
+ or similar. Press it and copy the HTTP link, we'll use it as the API-KEY in our
929
+ next step.
928
930
929
931
With our wallet funded fake ETH, we can go ahead and change our Hardhat
930
932
configuration file. Go into your project's main directory and open
@@ -933,8 +935,7 @@ configuration file. Go into your project's main directory and open
933
935
We are going to replace our file with this:
934
936
935
937
``` jsx
936
- require (" @nomicfoundation/hardhat-chai-matchers" );
937
- require (" @nomiclabs/hardhat-ethers" );
938
+ require (" @nomicfoundation/hardhat-toolbox" );
938
939
939
940
const WALLET_PRIVATE_KEY = " YOUR-PRIVATE-KEY-DONT-SHARE" ;
940
941
@@ -954,19 +955,19 @@ module.exports = {
954
955
};
955
956
```
956
957
957
- And you need to fill those 2 global variables with your own for hardhat to
958
- communicate correctly to the network.
958
+ And you'll need to set the two global variables using the ` const ` keyword with
959
+ your own values for Hardhat to communicate correctly to the network.
959
960
960
961
We have already gone through how to get your API KEY.
961
962
962
963
For your wallet's private key, the most sensitive data of the project, you need
963
- to open Metamask, click on the three dots next to your Account Name , and then on
964
- Account Details , then click on Export Private Key . It will ask for your Metamask
965
- password ( the one you use to open it, NOT your seed phrase) . It also shows you a
966
- notice so you know that you are entering the danger zone . Confirm and you'll be
967
- able to copy your private key. Paste it in to our ` hardhat.config.js `
964
+ to open Metamask, click on the three dots next to your _ Account Name _ , and then
965
+ on _ Account Details _ , then click on _ Export Private Key _ . It will ask for your
966
+ Metamask password - the one you use to open it, NOT your seed phrase. It also
967
+ issues a warning to 'Never disclose this key' . Confirm and you'll be able to
968
+ copy your private key. Paste it in to our ` hardhat.config.js `
968
969
969
- Please, if you are already a developer and you plan to use Git to store your
970
+ Please, if you are already a developer, and you plan to use Git to store your
970
971
project, don't store your ` hardhat.config.js ` on it, because you will have your
971
972
private key there.
972
973
@@ -982,7 +983,7 @@ private key there.
982
983
</SideDrawer >
983
984
<br />
984
985
985
- Ok. We are ready, let's deploy to the Goerli testnet!
986
+ Ok. We are ready, let's deploy to the Sepolia testnet!
986
987
987
988
Now we need to run our deploy.js script and the deployment is going to cost us
988
989
some ETH - test ETH, don't worry - from our wallet, since we are storing
@@ -994,7 +995,7 @@ deploy, delete all the lines we added to test the minting.
994
995
Run:
995
996
996
997
``` bash
997
- npx hardhat run scripts/deploy.js --network goerli
998
+ npx hardhat run scripts/deploy.js --network sepolia
998
999
```
999
1000
1000
1001
This is the output i got in my console:
@@ -1010,7 +1011,7 @@ next project we will learn about tools to collaborate and store your projects
1010
1011
online.
1011
1012
1012
1013
So now we can go and explore the chain to find your contract (and mine too!).
1013
- Just go to [ Goerli Etherscan] ( https://goerli .etherscan.io/ ) (or
1014
+ Just go to [ Sepolia Etherscan] ( https://sepolia .etherscan.io/ ) (or
1014
1015
[ Opensea] ( https://testnets.opensea.io/ ) ) and search for the address of our
1015
1016
deployed contract.
1016
1017
0 commit comments