> For the complete documentation index, see [llms.txt](https://docs.bitcichain.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bitcichain.com/developers/build-on-bitcichain/using-hardhat.md).

# Using Hardhat

## Creating and Deploying an ERC-20 Token on BitciChain with Node.js and Hardhat

### Introduction

This guide will take you through the process of creating and deploying an ERC-20 token on the Ethereum blockchain using Node.js and Hardhat.

#### Prerequisites

* [ ] Node.js installed on your machine.
* [ ] Familiarity with basic Ethereum concepts.
* [ ] A code editor of your choice (e.g., Visual Studio Code).

### Step 1: Set Up the Project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Run `npm init` to initialize a new Node.js project. Follow the prompts to set up your `package.json` file.

### Step 2: Install Hardhat

1. Install Hardhat: Run `npm install --save-dev hardhat`.
2. Run `npx hardhat` to create the Hardhat project structure. Follow the prompts to set up your Hardhat configuration.

### Step 3: Write the ERC-20 Smart Contract

1. In the `contracts` directory, create a new file (e.g., `MyToken.sol`).
2. Write the ERC-20 token smart contract code in Solidity. Below is a basic example:

```solidity
// MyToken.sol
pragma solidity ^0.8.0;

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

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000000 * 10**18);
    }
}
```

### Step 4: Install OpenZeppelin Contracts

1. Run `npm install @openzeppelin/contracts` to install the OpenZeppelin Contracts library.

### Step 5: Configure Hardhat

1. In the `hardhat.config.js` file, add bitcichain as a new network.

<pre class="language-javascript"><code class="lang-javascript">require('@nomiclabs/hardhat-waffle');
require('@openzeppelin/hardhat-upgrades');

module.exports = {
<strong>    networks: {
</strong>        bitcichain: {
            chainId: 1907,
            url: "https://rpc.bitci.com",
            accounts: ["your-private-key"],
        },
    }
};
</code></pre>

### Step 6: Deploy the ERC-20 Token

1. In the `scripts` directory, create a new deployment script (e.g., `deploy.js`).

```javascript
// deploy.js
async function main() {
    const MyToken = await ethers.getContractFactory("MyToken");
    const myToken = await MyToken.deploy();

    console.log("MyToken deployed to:", myToken.address);
}

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

2. Run the deployment script: `npx hardhat run scripts/deploy.js --network bitcichain`.

### Step 7: Interact with the Deployed ERC-20 Token

1. Use the Hardhat console or create a separate script to interact with the deployed ERC-20 token.

```javascript
// interact.js
async function main() {
    const MyToken = await ethers.getContractFactory("MyToken");
    const myToken = await MyToken.attach("0xYourDeployedTokenAddress");

    const balance = await myToken.balanceOf("0xYourAddress");
    console.log("Your balance:", balance.toString());
}

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

2. Run the interaction script: `npx hardhat run scripts/interact.js --network bitcichain`.

Congratulations! You have created and deployed an ERC-20 token on BitciChain using Node.js and Hardhat.

### Additional Resources

* [Hardhat Documentation](https://hardhat.org/)
* [OpenZeppelin Contracts Documentation](https://docs.openzeppelin.com/contracts)
