# Hardhat Installation & Deploy your First L1X EVM FT Contract

Step 1: Initialize a New Project

1. **Create a New Directory** (if you're starting fresh):

   ```bash
   mkdir L1XEVMERC20
   cd L1XEVMERC20

   ```
2. **Initialize a new NPM project**:

   ```bash
   npm init -y

   ```

#### Step 2: Install Hardhat and Set Up the Project

1. **Install Hardhat**:

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

   ```
2. **Set up the Hardhat project**: Run the setup command and choose to create a TypeScript project:

   ```bash
   npx hardhat

   ```

   When prompted, select to create a TypeScript project. Follow the prompts to add a `.gitignore` and install the project's dependencies.

#### Step 3: Install Necessary Plugins and Dependencies

1. **Install TypeScript-related dependencies**:

   ```bash
   npm install --save-dev ts-node typescript @types/node @types/mocha

   ```
2. **Install OpenZeppelin Contracts**:

   ```bash
   npm install @openzeppelin/contracts

   ```
3. **Install Ethers and Hardhat Ethers** (ensure compatibility):

   ```bash
   npm install --save-dev ethers @nomicfoundation/hardhat-ethers

   ```

#### Step 4: Configure TypeScript

1. **Create a `tsconfig.json` file** in your project root with the following content:

   ```json
   {
     "compilerOptions": {
       "target": "ES2020",
       "module": "CommonJS",
       "strict": true,
       "esModuleInterop": true,
       "outDir": "dist",
       "noImplicitAny": true
     },
     "include": [
       "./scripts/**/*",
       "./test/**/*",
       "./hardhat.config.ts"
     ],
     "exclude": ["node_modules"]
   }

   ```

#### Step 5: Write Your Smart Contract

1. **Create an ERC20 token** using OpenZeppelin: Create a `contracts/Token.sol` file:

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

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

   contract Token is ERC20 {
       constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
           _mint(msg.sender, initialSupply);
       }
   }

   ```

#### Step 7: Compile Your Contracts

1. **Compile your project**:

   ```bash
   npx hardhat compile

   ```
2. **Write deployment scripts or tests** as needed, using the setup you've created. Example Provided below.

```tsx
// scripts/deploy_myerc20.js
const { ethers } = require("hardhat");

async function main() {
  const [deployer] = await ethers.getSigners();

  console.log("Deploying contracts with the account:", deployer.address);

  const Token = await ethers.getContractFactory("Token");
  const initialSupply = "1000000000000000000000"; // 1000 tokens
  const name = "L1XToken";
  const symbol = "XT";
  const decimals = 18;

  const token = await Token.deploy(
    initialSupply,
    // name,
    // symbol,
    // decimals
  );

  // await token.waitForDeployment();

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

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

```

Sample Hardhat Config TS File

```tsx
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import '@nomicfoundation/hardhat-ethers';

// Enter your Private Key here
const PRIVATE_KEY = 'xx'; 

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.20",
    settings: {
      optimizer: {
        enabled: true,
      },
    },
  },
  networks: {
    localhost: {
      url: 'localhost:8545',
    },
    l1xTestnet: {
      url: '<https://v2-testnet-rpc.l1x.foundation>',
      accounts: [PRIVATE_KEY], 
    },
  },
};

export default config;

```

\-- Check Endpoint for L1X TestNet Faucet Before Deployment

Deployment Bash

```bash
npx hardhat run scripts/deploy.ts --network l1xTestnet

```

<figure><img src="https://2096665269-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMkJc2c6dQwd5FCUJMI6n%2Fuploads%2FSJT2fvWRqiHlQqemqbwO%2FConsole%20Output.jpg?alt=media&#x26;token=0c02aa03-9da8-455e-8857-f5bc54e7c504" alt=""><figcaption><p>Deployment Result</p></figcaption></figure>
