# Deployment with Hardhat

## Overview

Hardhat is a development tool for Ethereum, aiding in smart contract creation with features for compiling, testing, debugging, and deployment of Solidity code.

Clone the tutorial at <https://github.com/MANTRA-Chain/omstead-hardhat-deployment-tutorial> to get started.

## Prerequisite

Install the dependencies

```
npm install --save-dev hardhat
npm install --save-dev @nomicfoundation/hardhat-toolbox
```

## **Using Hardhat Ignition**

1. In your Hardhat project, add Remote Network to `hardhat.config.js` for MANTRA Omstead (COSMOS+EVM)

<pre class="language-javascript"><code class="lang-javascript"><strong>require("@nomicfoundation/hardhat-toolbox");
</strong>
const { vars } = require("hardhat/config");

const TEST_PRIVATE_KEY = vars.get("TEST_PRIVATE_KEY");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.28",
  networks: {
    omstead: {
      url: `https://evm.dukong.mantrachain.io/`,
      chainId: 5887,
      accounts: [TEST_PRIVATE_KEY]
    },
  }
};
</code></pre>

Example on how to configure variables for user-specific values in Hardhat:

```
npx hardhat vars set TEST_PRIVATE_KEY
✔ Enter value: ********************************
```

2. **Compile**

```
npx hardhat compile
```

3. **Set Up Ignition Modules:**

*(We have created a sample module for you in the tutorial repository)*

* Create a directory named `ignition` in the project's root directory.
* Inside the `ignition` directory, create another directory named `modules`.
* Within the `modules` directory, create a `<YourFile>.js` file.

Example directory structure:

```
./ignition/modules/<YourFile>.js
```

4. **Deploy**

To tell Hardhat to connect to a specific Ethereum network, you can use the `--network` parameter when running any task, like this:

```bash
npx hardhat ignition deploy ./ignition/modules/Token.js --network omstead
```

Example result from running the above command

```
$ npx hardhat ignition deploy ./ignition/modules/USDC.js --network omstead

✔ Confirm deploy to network omstead (5887)? … yes
Hardhat Ignition 🚀
Deploying [ TokenModule ]

Batch #1
  Executed TokenModule#Token

[ TokenModule ] successfully deployed 🚀

TokenModule#Token - <0xHash of the deployed contract>
```
