# Using Hardhat

There are a few technical requirements before we start. Please install the following:

* [Node.js v10+ LTS and npm](https://nodejs.org/en/) (comes with Node)
* [Git](https://git-scm.com/)

Once we have those installed, To install **Hardhat**, you need to create an npm project by going to an empty folder, running npm init, and following its instructions. Once your project is ready, you should run

Copy

```
$ npm install --save-dev hardhat
```

To create your Hardhat project run `npx hardhat` in your project folder Let’s create the sample project and go through these steps to try out the sample task and compile, test and deploy the sample contract.

The sample project will ask you to install hardhat-waffle and hardhat-ethers.You can learn more about it [in this guide](https://hardhat.org/getting-started/#quick-start)

#### **Hardhat-config** <a href="#hardhat-config" id="hardhat-config"></a>

* Go to hardhat.config.js
* Update the hardhat-config with CTEX-network-credentials
* Create .env file in the root to store your private key
* Add CTEXscan API key to .env file to verify the contract on CTEXscan. You can generate an API key by [creating an account](https://ignitescan.com/register)

Copy

```
Explainrequire('dotenv').config();
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-etherscan");

module.exports = {
  defaultNetwork: "Ctex",
  networks: {
    hardhat: {
    },
    ctex: {
      url: "https://test1ctexrpc.com",
      accounts: [process.env.PRIVATE_KEY]
    }
  },
  etherscan: {
    apiKey: process.env.ctexSCAN_API_KEY
  },
  solidity: {
    version: "0.8.3",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
}
```

Make sure to update the Solidity compiler version here based on what is required in your contract(s).

#### **Compile Smart contract file** <a href="#compile-smart-contract-file" id="compile-smart-contract-file"></a>

Copy

```
$ npx hardhat compile
```

#### **Deploying on ctex Network** <a href="#deploying-on-ignite-network" id="deploying-on-ignite-network"></a>

Run this command in root of the project directory:

Copy

```
$ npx hardhat run scripts/sample-script.js --network ctex
```

Contract will be deployed on CTEX **Chain Testnet**, it look like this:

Copy

```
Compilation finished successfully
Greeter deployed to: 0xF0B2F5AbE5A52B5BF85B2320A730D1Ed714c1af3
```

> Remember your address would differ, Above is just to provide an idea of structure. **Congratulations!** You have successfully deployed Smart Contract. Now you can interact with the Smart Contract.

You can check the deployment status here: <https://testnet-rpc.ctexscan.com>

#### **Verifying contract on ctexscan** <a href="#verifying-contract-on-ignitescan" id="verifying-contract-on-ignitescan"></a>

Run the following commands to quickly verify your contract on ctexscan. This makes it easy for anyone to see the source code of your deployed contract. For contracts that have a constructor with a complex argument list, see [here](https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html).

Copy

```
$ npm install --save-dev @nomiclabs/hardhat-etherscan
$ npx hardhat verify --network ctex 0xF0B2F5AbE5A52B5BF85B2320A730D1Ed714c1af3
```

> Remember to update your address to your own deployed contract address. When the command is successful, you will see your contract verified on ctexscan!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ctex-network.gitbook.io/developer-documentation/depolying-ctex-chain/using-hardhat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
