# Hardhat

[Hardhat](https://hardhat.org) is another essential tool that should be found in every dApp developer's arsenal. Hardhat allows seamless deployment of smart contracts, running of tests, and debugging outside of live environments.&#x20;

One of the biggest advantages of Hardhat is its flexibility - there is a series of plugins available for different types of developers, and Hardhat's extensible ecosystem allows for efficient tooling.&#x20;

This guide assumes that the reader has at least some familiarity with the Solidity programming language for smart contracts, and general dApp development on the Ethereum network.&#x20;

*The following is a short guide for deploying a smart contract using Hardhat. The best solution is to use a development environment like VSCode for an optimal deployment experience.*

**1.** First of all, make sure you have HardHat set up on your local machine. Check out this guide if you encounter problems: <https://hardhat.org/hardhat-runner/docs/guides/project-setup>

**2.** There are 3 files that you will have to edit. First, create a Solidity file under the contracts folder. You can right click on the folder and create a new file. For this example, we named it ***HHToken.sol***

<figure><img src="https://4145461321-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXnmMY63g38TZM2uGNbd1%2Fuploads%2FohBXxEUNiHCBLCYCN2KW%2F5.png?alt=media&#x26;token=ba692fe9-56ff-4fa2-ba74-36b56ae0b4fe" alt=""><figcaption></figcaption></figure>

**3.** Paste this piece of simple contract code in your ***HHToken.sol*** equivalent file:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";\

contract HHToken is ERC20, ERC20Burnable, Ownable {
    
    constructor() ERC20("HHToken", "HHT") {
        _mint(msg.sender, 1000 * 10 ** 18);
    }
    
    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}
```

**4.** Once you’re done, go to the scripts folder, then look for ***deploy.js***. As part of the setting up Hardhat, there are already some lines in the that file. You will just have to edit some variables like the ones below:&#x20;

```javascript
const hre = require("hardhat");

async function main() {

    const Token = await hre.ethers.getContractFactory("HHToken");
    const token = await Token.deploy();
    await token.deployed();

    console.log("Token deployed to:", token.address);
}

main()
  .then(() => process.exit(0));
  .catch((error) => {
    console.error(error);
    process.exit(1);
});
```

{% hint style="info" %}
Make sure that for *getContractFactory* you enter the contract name of your token.
{% endhint %}

**5.** Once you have entered your contract name, go to the main folder and look for the file named ***hardhat.config.js***. Enter the BlockX Network details:

* **RPC**: <https://web3.blockxnet.com&#x20>;
* **Chain ID**: 100&#x20;

```javascript
module.exports = {
  defaultNetwork: "Mainnet",
  networks: {
    blockx: {
      url: "https://web3.blockxnet.com",
      chainId: 100,
      gasPrice: 2000000000,
      accounts: [privKey]
    },
```

It would be advisable to try deploying using Atlantis network first as it is the Testnet.&#x20;

\
RPC URL: <https://atlantis-web3.blockxnet.com>

Chain ID: 50

For the accounts, we stored our private key to a variable and named it *privKey*. You can also put your private key there. This private key should belong to the account of the one who deploys the contract, so make sure it has some BCX tokens.&#x20;

**6.** Open the **Terminal i**n your VSCode so you can enter a deployment command like the following:&#x20;

```bash
npx hardhat run --network blockx scripts/deploy.js 
```

&#x20;We named the network `blockx` in the ***hardhat.config.js*** file, which is why we used `blockx` after the `–-network` flag.&#x20;

**7.** You should now see an output like this:

<figure><img src="https://4145461321-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXnmMY63g38TZM2uGNbd1%2Fuploads%2Fds6Usf419YIvJHx570ts%2F1.png?alt=media&#x26;token=defe07be-3c0a-4df0-ba2f-57fa08c7ae96" alt=""><figcaption></figcaption></figure>

That’s it, you’ve successfully deployed your token using Hardhat on the BlockX Network! You can use [**https://explorer.blockxnet.com**](https://explorer.blockxnet.com) if you want to see more information on your newly deployed contract.
