L1X Developer SDK
Get Started
Get Started
  • L1X VM SDK
    • L1X Native SDK for L1X VM
      • Set up Environment
        • Pre-Requisites
        • Installation
          • Install Cargo L1X
            • Ubuntu and Windows (WSL)
            • Mac (Intel and Silicon)
          • Install L1X CLI (Beta)
      • Build your First Smart Contract on L1X VM
        • Common Flags and Arguments
    • L1X CLI Methods
  • L1X EVM SDK
    • Pre-Requisites
    • Hardhat Installation & Deploy your First L1X EVM FT Contract
  • L1X Typescript SDK
    • L1X Library
      • L1X Typescript SDK
      • Account Methods
        • How to import wallet using mnemonic?
        • How to import wallet using private key?
      • Core Methods
        • How to get Account State?
        • How to get block information by block number?
        • How to get chain state?
        • How to get events?
        • How to get current nonce?
        • How to get account transactions?
        • How to get the transaction recipt?
        • How to broadcast transactions?
      • L1X VM Methods
        • How to deploy a VM contract?
        • How to initialise a VM contract?
        • How to make VM readonly calls?
        • How to make VM contract state changing calls?
      • L1X EVM Methods
        • How to initialise a smart contract?
        • How to make an EVM contract state changing call?
        • How to make EVM read only calls?
      • Other Methods
        • Native Token Methods
          • How to transfer native token?
          • How to get native token balance?
          • How to get signed payload for transfer?
        • Fungible Token Methods
          • How to create fungible tokens?
          • How to mint fungible token?
          • How to give approval to fungible token?
          • How to get fungible token attributes?
          • How to get a fungible token balance?
          • How to get an allowence of fungible tokens?
          • How to transfer fungible tokens?
          • How to use transfer from of fungible token?
        • Non-fungible Token Methods
          • How to Create a Non-Fungible Token?
          • How to mint a Non-Fungible Token?
          • How to get the balance of a Non-Fungible token?
          • How to get the attribute of a Non-Fungible token?
          • How to approve a spender to manage a specific Non-Fungible token?
          • How to set or revoke approval for a specific operator to manage all tokens of the sender?
          • How to get the owner of a Non-Fungible token by its ID?
          • How to Transfer a Non-Fungible token from one address to another?
          • How to burn an existing Non-Fungible Token?
  • Endpoints
  • Configuring MetaMask with L1X Network
Powered by GitBook
On this page
  1. L1X EVM SDK

Hardhat Installation & Deploy your First L1X EVM FT Contract

You can use Hardhat and Ethers to Compile, Deploy and Interact with Contracts on L1X EVM.

Step 1: Initialize a New Project

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

    mkdir L1XEVMERC20
    cd L1XEVMERC20
    
  2. Initialize a new NPM project:

    npm init -y
    

Step 2: Install Hardhat and Set Up the Project

  1. Install Hardhat:

    npm install --save-dev hardhat
    
  2. Set up the Hardhat project: Run the setup command and choose to create a TypeScript project:

    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:

    npm install --save-dev ts-node typescript @types/node @types/mocha
    
  2. Install OpenZeppelin Contracts:

    npm install @openzeppelin/contracts
    
  3. Install Ethers and Hardhat Ethers (ensure compatibility):

    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:

    {
      "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:

    // 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:

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

// 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

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

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

PreviousPre-RequisitesNextL1X Library

Last updated 1 year ago

Deployment Result