# Deploy Smart Contracts with Hardhat

### **Prerequisites**

Before you begin, ensure you have:

* VS Code: code-editor
* Node.js :

  This is like the secret language that lets you talk to the blockchain world.

  Open your terminal/CLI and type:

```jsx
node -v
```

If it answers you with a version number, you’re good. If it gives you the silent treatment, go to [**https://nodejs.org/**](https://nodejs.org/) **an**d d[**ownload it.**](https://nodejs.org/)<br>

* Metamask wallet

  Think of this like your wallet, but to store your crypto instead of real cash. Get it here: [https://metamask.io/](https://metamask.io/**)<br>

  Set it up. Save your seed phrase. Hide it like treasure.

  (*Seriously. Don't lose it. Don't share it. Ever.*)<br>
* HeLa Testnet faucet

  You’ll need some fake money (test tokens) to pay for gas while we play.

### **Create your project folder:**

Developing Your First Token on HeLa Chain

If you have developed dApps on Ethereum or `any EVM compatible chain` before, you will feel at home. It is exactly the same. But if you are new, don’t worry, this document will help you embark on your first token development on HeLa chain. There many platforms and utilities that you can use to develop token. For example: REMIX, Truffle, HardHat, Foundry, etc. We will use Hardhat for our first token. Visit

Our first program is to develop our first Token on HeLa Chain

Step:1 Install Hardhat:

```jsx
mkdir hela-token
cd hela-token
npm init -y
npm install --save-dev hardhat
npx hardhat
```

Choose "Create a basic sample project"

It will give you options like:

```jsx
✔ What do you want to do? 
  - Create a JavaScript project
  - Create a TypeScript project
  - ...

```

Select: **“Create a JavaScript project”** (use arrow keys and hit enter)

#### **It will create some files for you.**

Once done, you should see a folder structure like:

```jsx
contracts/
scripts/
hardhat.config.js
package.json
...

```

**Pause. Take a breath. You’ve done a LOT already, and and**

> Congrats. You just built yourself a smart contract workspace without writing a single line of code.

### **Install OpenZeppelin Contracts**

OpenZeppelin is a library of pre-built, secure smart contracts. We’ll use it to create your token. Since we’re building a token, use OpenZeppelin’s ERC20 standard:

```jsx
npm install @openzeppelin/contracts

```

* OpenZeppelin gives us pre-built secure templates.
* Because honestly, you don’t want to write token code from scratch.
* 99% of crypto projects use these same templates.

### **Go to your project folder. Inside, you will see a contracts/ folder.**

Inside `contracts/`, create a new file called:

```jsx
MyToken.sol
```

### Write your TOKEN Contract

Inside `contracts/`, create a new file `MyToken.sol`:

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyFirstHeLaToken", "HLT") {
        _mint(msg.sender, initialSupply);
    }
}
```

Currently, they only support 0.8.9 solidity version. For Ref: [\*\*](https://docs.helalabs.com/build-on-us/build-on-testnet)<https://docs.helalabs.com/build-on-us/build-on-testnet**>

**Explanation:**

* `ERC20("MyFirstHeLaToken", "HLT")` — this is your token name and symbol.
* `initialSupply` — how many tokens you want to create at the start.
* `msg.sender` — the wallet address that deploys the contract will receive all tokens.

**You can change the token name and symbol to whatever you want.**

For example:

```jsx
ERC20("BananaCoin", "BAN")
```

### **Write deployment script**

Let’s write instructions for Hardhat to deploy this contract.

```jsx
npm install ethers
```

* We import `{ ethers }` from `"ethers"` (not from hardhat directly)
* In Ethers v6+, `parseEther` is now used like: `ethers.parseEther("1000000")` (no `utils`)

Inside `scripts/`, edit `deploy.js` (or create it if not present):

```jsx
const hre = require("hardhat");
const { ethers } = require("ethers");

async function main() {
  const initialSupply = ethers.parseEther("1000000"); // 1 million tokens

  const Token = await hre.ethers.getContractFactory("MyToken");
  const token = await Token.deploy(initialSupply);

  // Wait for the contract to be mined
  await token.waitForDeployment();

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

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

```

**Explanation:**

* `initialSupply` — we're creating **1 million tokens** (you can change this amount).
* `hre.ethers.utils.parseEther("1000000")` — converts "1 million tokens" into the smallest units ("wei").
* `getContractFactory("MyToken")` — tells Hardhat to deploy the `MyToken.sol`contract you wrote.

### **Configure Hardhat to connect to HeLa Chain**

Now we need to tell Hardhat where HeLa Testnet lives.

Edit `hardhat.config.js` and add the network config for HeLa.

#### **1. Install dotenv package**

It’s safer to store your private key in a `.env` file, even for testnet practice:

```jsx
npm install dotenv
```

#### **2. Create a file called `.env` in your project root folder.**

Inside `.env`, paste:

```jsx
PRIVATE_KEY=27015ed9348599b64f1c5f56389e2105072a3a061a64611
```

Where do you get this private key?

Open Metamask → Account Details → Export Private Key.

(*Never share your private key with anyone except your trusted computer.*)

#### **3. Edit your `hardhat.config.js`**

Open `hardhat.config.js` and replace the contents with this:

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

module.exports = {
  solidity: "0.8.20",
  networks: {
    hela: {
      url: "<https://testnet-rpc.helachain.com>",
      chainId: 666888,
      accounts: [process.env.PRIVATE_KEY]
    }
  }
};

```

Explanation:

* We loaded your private key securely from `.env`
* We added HeLa Testnet RPC URL & Chain ID
* Now Hardhat knows exactly how to deploy to HeLa Testnet.

#### 4. Deploy Your Token on HeLa Testnet

Make sure:

* You’re inside the project folder
* Your `.env` file exists
* You have some testnet $HELA (for gas)

From here you can get some $HELA token for your gas : [**https://testnet-faucet.helachain.com**](https://testnet-faucet.helachain.com/)

what you need to do is just simple paste your wallet address, make sure you have setup the custom network in your wallet ( in our case we used metamask wallet ) \
Ref : [https://docs.helalabs.com/build-on-us/metamask](https://docs.helalabs.com/build-on-us/metamask**)<br>

1. Run the deployment command:

```jsx
npx hardhat run scripts/deploy.js --network hela
```

What you should see in your terminal:

```jsx
Token deployed to: 0xYourContractAddressHere
```

2. Go check it on HeLa Testnet Explorer : [https://testnet-blockexplorer.helachain.com/](https://testnet-blockexplorer.helachain.com/**)

## Support :&#x20;

If you encounter any issues during setup or require assistance, please join the [**HeLa Developer Community**](https://discord.gg/NEBtTztJCj) for direct support and guidance.
