# Deploy a Token Contract - ERC20

Deploying an ERC-20 token on Vanar chain is a straightforward process if you have some experience with Ethereum development. Below is a step-by-step tutorial on how to deploy an ERC-20 token using Hardhat, a popular Ethereum development framework. Make sure you have Node.js and npm installed before you begin. Below are the libraries and tools used for this tutorial:

* **OpenZeppelin** - used for standard ERC20 base contract that is well tested and used by many production scale projects
* **Hardhat** - is a tool and an environment that helps you compile, build, deploy and test you smart contracts along many other features.

#### Prerequisites:

1. Node.js and npm installed on your machine.
2. Basic knowledge of Solidity and Ethereum development.

#### Step 1: Set Up a New Hardhat Project

If you don't already have a Hardhat project, you can create one by following these steps:

* Create a new directory for your project and navigate to it in the terminal:

{% code overflow="wrap" %}

```bash
mkdir my-erc20-token
cd my-erc20-token
```

{% endcode %}

* Initialize a new Node.js project with npm:

```bash
npm init -y
```

* Install Hardhat as a development dependency:

{% code overflow="wrap" %}

```bash
npm install --save-dev hardhat
```

{% endcode %}

* Initialize Hardhat in your project:

{% code overflow="wrap" %}

```bash
npx hardhat
```

{% endcode %}

Follow the prompts to configure your project.

#### Step 2: Write the ERC-20 Token Contract

Now, you'll need to create a Solidity smart contract for your ERC-20 token. Create a new file called `Token.sol` in the `contracts` directory.

Here's a basic example of an ERC-20 contract:

{% code overflow="wrap" %}

```solidity
// contracts/Token.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract TestToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Test Token", "MNA") {
        _mint(msg.sender, initialSupply);
    }
}
```

{% endcode %}

* Make sure to install OpenZeppelin's ERC-20 library if you haven't already:

{% code overflow="wrap" %}

```bash
npm install @openzeppelin/contracts
```

{% endcode %}

#### Step 3: Configure Hardhat

In your Hardhat project, configure the deployment by modifying the `hardhat.config.js` file. You can specify the network, account, and other settings for deployment.

Here's an example configuration:

{% code overflow="wrap" %}

```javascript
// hardhat.config.js
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-etherscan");

module.exports = {
  networks: {
    // Add network configurations here (e.g., for local development, testnets, or mainnet).
    VANAR_TESTNET:{
      url: "RPC_VANAR_VANGAURD",
      accounts: ["PRIVATE_KEY_OF_THE_DEPLOYER"],
      chainId: 7860
    }
  },
  etherscan: {
    apiKey: "YOUR_ETHERSCAN_API_KEY", // Replace with your Etherscan API key
  },
  vanar: {
    apiKey: "YOUR_VANAR_API_KEY", // Replace with your VANAR API key
  }
  solidity: "0.8.0",
};
```

{% endcode %}

**Step 4: Deploy the ERC-20 Token**

Now, you can deploy your ERC-20 token using Hardhat. Create a deployment script in the `scripts` directory (e.g., `deployERC20.js`) to deploy the contract:

{% code overflow="wrap" %}

```javascript
mkdir my-erc20-token
// scripts/deployERC20.js
const { ethers, upgrades } = require("hardhat");

async function main() {

  const maxSupply = 1000000 * (10 ** 18); // To mint 1,000,000 tokens

  const [deployer] = await ethers.getSigners();

  console.log("Deploying TestToken from account:", deployer.address);

  const TestToken = await ethers.getContractFactory("TestToken");
  const testToken = await TestToken.deploy(maxSupply); // Initial supply

  console.log("TestToken deployed to:", testToken.address);

  await testToken.deployed();
}

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

```

{% endcode %}

#### Step 5: Deploy the Token

Run the deployment script using Hardhat:

{% code overflow="wrap" %}

```bash
npx hardhat run scripts/deployERC20.js --network <network_name>
```

{% endcode %}

Replace `<network_name>` with the configured Vanar network you want to deploy the token on.

####

That's it! You've deployed an ERC-20 token using Hardhat on Vanar. Make sure to test your token and handle any additional functionalities such as transfers, approvals, and more if needed.


---

# 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://docs.vanarchain.com/builders/for-developers/tutorials/deploy-a-token-contract-erc20.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.
