Deploying a Contract Using Hardhat
Last updated
Last updated
Hardhat is a development framework for Ethereum software, providing various tools for smart contract development, compilation, debugging, and deployment. Since dKargo is compatible with Ethereum's EVM, smart contracts can be deployed on the dKargo network.
This guide will walk through the process of building a Wallet dApp using Hardhat and dKargo Warehouse.
Prerequisites
Node.js & npm/yarn:
Installed from .
Hardhat: Development environment for Ethereum.
Install with:
Initialize a new Hardhat project
Below is an example of the Hardhat project folder structure:
Counter.sol
ContractCreate a new file named Counter.sol
inside the contracts
folder.
Copy and paste the following code into the file.
The following contract implements a simple function to set the number
variable.
Create a new file named Counter.js
inside the ./ignition/modules
folder.
Copy and paste the following code into the file.
Add the necessary plugins and configurations to hardhat.config.js
.
require('dotenv').config() :
Loads environment variables from the .env
file.
accounts: [process.env.PRIVATE_KEY] :
Passes the private key stored in the .env
file.
Add the following code to the file, and ensure that .env
is included in the gitignore
file to prevent exposing sensitive information.
Compile counter.sol
.
Deploy the counter.sol
contract to the Warehouse testnet:
Check the transaction details of the deployed contract.
In Ethereum and other EVM-based blockchains, smart contracts are often verified using Hardhat's verify
function.
Install for managing environment variables.
This script follows the and is responsible for deploying the contract.
Search for the transaction information on
However, dKargo Chain utilizes , a block explorer optimized for logistics services, which is not compatible with Hardhat’s verify
function.
To ensure transparency of deployed contracts, the feature provided by can be used instead.