Coding Time -
For coding, we will go step by step.
[Make sure you have VSCode and Solidity extension installed]
Step 1:-
Let's delete some unwanted code first -
- The file sample-test.js under test
- Greeter.sol under contracts
Step 2:-
Open the project up in VSCode, and let's get to writing our NFT contract.
Step 3:-
Go to the contacts directory and create a file named HelloNFT.sol
Now type this code,
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract MyEpicNFT {
constructor() {
console.log("This is my NFT contract. Woah!");
}
}
Let's understand the code line by line.
// SPDX-License-Identifier: UNLICENSED
SPDX License Identifiers can be used to indicate relevant license information at any level, from package to the source code file level. Accurately identifying the license for open source software is important for license compliance.
pragma solidity ^0.8.0;
This is the version of the Solidity compiler we want our contract to use which should be the same as the compiler in hardhat.config.js.
import "hardhat/console.sol";
Adding the debug feature for our project provided by hardhat.
contract HelloNFT {
constructor() {
console.log("Say Hello to my first NFT Contract");
}
}
Once we initialize this contract for the first time, that constructor will run and print out "Say Hello to my first NFT Contract".
So we have made our smart contract in the 3 steps :)
Next, we will run it!