set up hardhat

~ 2 min.

01.03.2023
edit
image

npm init -y
npm install --save-dev hardhat

run below command in terminal -> choose create a javaScript project -> SPAM ENTER for all other options.

Terminal
npx hardhat

note: whenever you compile/run your smart contract, hardhat automatically gets the required version downloaded + installed for you -- pretty cool right!

  • node_modules - all the magical spells of Hardhat reside here
  • contracts - smart contracts are written here
  • scripts - deployment scripts are made here
  • test - testing scripts go here
  • create a file -- Hello.sol in contracts folder -- then, copy + paste the following code.

    ./contracts/Hello.sol
    // SPDX-License-Identifier: MIT
     
    pragma solidity ^0.8.17;
     
    import "hardhat/console.sol";
     
    contract Hello {
        string public message = "Hello World";
     
        function getMessage() public view returns (string memory) {
            return message;
        }
    }

  • install Solidity extension in VS code by Juan Blanco from here -- it will help in debugging + developing faster.
  • don't know how to write smart contracts? -- check this out.
  • you have a hardhat project all set up, damn! -- before doing some magical stuff with it, you actaully need to know how it all works, right? -- click here to expose Hardhat's magical tricks happening under the hood.