Hardhat
Deploy and Execute Smart Contracts using Hardhat
Let`s create and deploy Smart Contracts using Hardhat.
You can create Hardhat project as follows. After running 'npx hardhat', you select what type of project to create and set the the root path for the project. If You choose to add the '.gitignore file' or install the dependency module for the sample project, the necessary files are installed.
$ mkdir greeter
$ cd greeter
$ npm install --save-dev hardhat
$ npx hardhat
888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
👷 Welcome to Hardhat v2.13.0 👷
✔ What do you want to do? · Create a JavaScript project
✔ Hardhat project root: · /Users/trident/Projects/Solidity/hardhat-test
✔ Do you want to add a .gitignore? (Y/n) · y
✔ Do you want to install this sample project's dependencies with npm (hardhat @nomicfoundation/hardhat-toolbox)? (Y/n) · yAfter installation, the directory structure is as follows. Smart contracts will be located in contracts, deployed scripts in scripts, test code in tests, and compiled results in artifacts, cache. Set the network connection information, solidity compiler version information, and so on in hardhat.config.js.
The Lock.sol that is created by default is compiled as follows.
Run the test using Lock.js, which is created by default.
Deploying smart contracts uses deploy.js, which is provided by default. You need to set up a network to deploy in advance, but add the WEMIX3.0 Testnet and Mainnet to hardhat.config.js as shown below. If you save the private key of the account address that use for deployment, it is easy to work with, so we recommend that you create a test account and then send as many WEMIX as you need. How to extract private keys from a MetaMask is omitted here.
When you are ready, run the following command to deploy. Upon successful deployment, the smart contract address is output according to the preset log.