dKargo Docs
dKargo.ioWhitepaper
Docs ENG
Docs ENG
  • Welcome to dKargo
  • Run dKargo Node
    • Chain RPC
    • Installation Guide
    • Types of Chain Node
    • Full Node
    • Archive Full Node
    • Validator Node
  • Wallet Setup
    • Connectiong to MetaMask
    • Creating a wallet
    • Importing a Wallet
    • Adding the dKargo Network
  • Validator Operations
    • Validator Staking
    • Staking
    • Unstaking
    • Claim
  • Deploy Contract
    • How to deploy a contract
    • Deploying a Contract Using Remix-IDE
    • Deploying a Contract Using Hardhat
    • Deploying a Contract Using Foundry
  • ERC-20 BRIDGING
    • ERC-20 Bridging
    • Standard Gateway
    • Generic-custom Gateway
    • Custom Gateway
  • DKA Bridging
    • DKA Bridging
    • DKA Deposit
    • DKA Withdraw
  • Faucet
    • Faucet for Testnet Tokens
    • Claiming Testnet Tokens
  • Chain Snapshot
    • Download the Latest Chain Snapshot
  • Contract Address
    • Contract Address List
  • Bug Bounty
    • Bug Bounty Program
Powered by GitBook
On this page
  • Development Environment
  • Step 1 - Set Up a Hardhat Project
  • Step 2 - Writing the Counter.sol Contract
  • Step 3 - Updating the ignition file
  • Step 4 - Configuring Hardhat for dKargo Chain
  • Step 5 - Compile and Deploy
  • Step 6 - Viewing the Deployment Transaction
  • Verify Contract
  1. Deploy Contract

Deploying a Contract Using Hardhat

PreviousDeploying a Contract Using Remix-IDENextDeploying a Contract Using Foundry

Last updated 1 month ago

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.

When deploying a contract on any blockchain, the native token of that chain is required to pay gas fees. This applies to dKargo Chain as well. Before deploying on the dKargo testnet (Warehouse), developers can obtain $DKA testnet tokens via the faucet.

Development Environment

Prerequisites

  • Node.js & npm/yarn:

    • Installed from .

  • Hardhat: Development environment for Ethereum.

    • Install with:

    npm install --save-dev hardhat

Step 1 - Set Up a Hardhat Project

  1. Initialize a new Hardhat project

mkdir helloDka
cd helloDka
npx hardhat init
npm i dotenv
touch .env
  1. Below is an example of the Hardhat project folder structure:

/helloDka
├── README.md
├── contracts
|  └── Lock.sol
├── hardhat.config.js
├── ignition
|  └── modules
|     └── Lock.js
├── package-lock.json
├── package.json
└── test
   └── Lock.js

Step 2 - Writing the Counter.sol Contract

  • Create 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.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
contract Counter {
    uint256 public number;
 
    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }
 
    function increment() public {
        number++;
    }
}

Step 3 - Updating the ignition file

  • Create a new file named Counter.js inside the ./ignition/modules folder.

  • Copy and paste the following code into the file.

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
 
module.exports = buildModule("Counter", (m) => {
  const lock = m.contract("Counter");
 
  return { lock };
});

Step 4 - Configuring Hardhat for dKargo Chain

  1. 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.

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.24",
  networks: {
    warehouse: {
      url: "<https://it-full.dknote.net>",
      accounts: [process.env.PRIVATE_KEY],
    },
  },
  ignition: {
    requiredConfirmations: 1
  }
};

  1. Add the following code to the file, and ensure that .env is included in the gitignore file to prevent exposing sensitive information.

PRIVATE_KEY=YOUR KEY HERE WITH NO QUOTES

Step 5 - Compile and Deploy

  1. Compile counter.sol.

npx hardhat compile
  1. Deploy the counter.sol contract to the Warehouse testnet:

npx hardhat ignition deploy ./ignition/modules/Counter.js --network warehouse

Step 6 - Viewing the Deployment Transaction

  1. Check the transaction details of the deployed contract.

npx hardhat ignition transactions chain-2465001

Verify 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.

Node.js
dotenv
Hardhat Ignition standard
dScanner
dScanner
Verify Contract
dScanner