... | ... | @@ -58,40 +58,27 @@ To simplify object access in MongoDB for our project, we utilize [Mongoose](http |
|
|
|
|
|
## Hardhat
|
|
|
|
|
|
To develop and deploy our smart contract we are using [Hardhat](https://hardhat.org), a popular development environment that offers tools for testing, compiling and deployment of Ethereum smart contracts. It also offers a built-in test network, the hardhat network that allows us to test our smart contract without having to worry about gas fees before deploying the smart contract to a real Ethereum network.
|
|
|
|
|
|
To add hardhat to your project, ensure that you're in the **nextjs-blog** directory and run the following command:
|
|
|
Whenever you created a smart contract or made changes to an existing smart contract, you first need to compile it using the following command:
|
|
|
|
|
|
```sh
|
|
|
npm install --save-dev hardhat
|
|
|
npx hardhat compile
|
|
|
```
|
|
|
|
|
|
You can verify that the dependency has been added correctly by checking the **package.json** file.
|
|
|
|
|
|

|
|
|
|
|
|
Then run the command:
|
|
|
When the smart contract is successfully compiled you can deploy it to a blockchain network using the command:
|
|
|
|
|
|
```sh
|
|
|
npx hardhat
|
|
|
npx hardhat --network sepolia run scripts/deploy.js
|
|
|
```
|
|
|
|
|
|
and choose the option to create an empty hardhat.config.js file to configure your Hardhat development environment. In this file, you can define various settings, such as the version of the Solidity compiler that Hardhat uses to compile your smart contracts, and specify the test networks that will be used for contract deployment. To interact with the blockchain in the Hardhat environment, you need to install and add the ethers.js library plugin to the hardhat.config.js file. This library will allow you to deploy the written smart contract and perform other interactions with the blockchain.
|
|
|
To install the plugin, run the following command and add the import to your hardhat.config.js file:
|
|
|
With **--network sepolia** you can specify the network on which the smart contract is deployed to and
|
|
|
**run scripts/deploy.js** is used to specify the script that executes the deployment.
|
|
|
|
|
|
After the smart contract is deployed you need to put the smart contract address in the .env file as value for the NEXT_PUBLIC_CONTRACT_ADDRESS variable:
|
|
|
|
|
|
```sh
|
|
|
npm install --save-dev @nomiclabs/hardhat-ethers
|
|
|
NEXT_PUBLIC_CONTRACT_ADDRESS = "smartContractAddress"
|
|
|
```
|
|
|
|
|
|
{height="450px"}
|
|
|
|
|
|
After that, you can create the folders **contract/** to store the source files for your smart contracts and **scripts/** where you can store the script for the contract deployment. Now, your directory should look like this:
|
|
|
|
|
|
{height="450px"}
|
|
|
|
|
|
For more information or if you are having trouble setting up your Hardhat Environment, visit the
|
|
|
[Hardhat Documentation](https://hardhat.org/docs)
|
|
|
|
|
|
## Deployment
|
|
|
### Database
|
|
|
|
... | ... | |