LogoLogo
Trade Now
  • Trade Now
  • 👋Welcome
    • About Demex
      • Roadmap
      • Terms and Conditions
      • Disclaimers
    • Getting Started
      • Depositing
      • Activate Account
      • One-Click Trading
  • 💰Demex Rewards
    • 🪂Demex Points
      • Spins
      • Wheel of Fortune and Loot Boxes
      • Squads
      • DMX Token
      • FAQs
    • 🏁Demex Endgame: 50,000,000 Demex Points
    • 💵Demex Credits
    • 🕙Past Events
      • 2022
        • Futures Trading Competition
          • Maker vs Taker #1
          • Maker vs Taker #2
        • Perpetuals Trading Competition
          • Top Gainers and Top Traders #1
          • Top Gainers and Top Traders #2
          • Top Gainers #3
      • 2023
        • Demex Trading Leagues
          • Demex Trading League
            • How to Register
          • Demex $100,000 Mega Marathon
            • Demex Trading League Vol 1
              • How to Register
            • Deposit Booster
            • Demex Trading League Vol 2
          • Demex Trading League (Round 3)
            • How to Register
          • Demex Trading League (Round 4)
          • LUNA Earn-A-Thon & Demex Trading League (Round 5)
          • Demex Trading League (Round 6)
          • SCRT Trading League
        • Earn-a-thons
          • Demex x StaFi ATOM Earn-A-Thon
          • Demex x Zilliqa ZIL Earn-A-Thon
            • How to Register
        • Trading Challenges
          • BNB Trading Challenge
            • How to generate your custom hashtag
          • NEO Trading Challenge
            • How to Register
          • OSMO Perp Trading Challenge
          • Perps Trading Challenge
        • Special Events
          • $500 Surprise Flash Promotion
          • Demex Incentivized Devnet (Ended)
            • Perp Pools Deposits
            • Base Vault and $CLP Staking
            • Fluo Dashboard (Deprecated)
              • Stake FLUO
              • Boost Rewards
              • esFLUO Rewards
            • Demex Trading League (Devnet)
              • How to Register
            • The HODL Lottery
              • How to Register
              • How to Count Your Tickets
      • 2024
        • Celestia Trading League
        • FOMO Points Booster
        • DeFi Points Booster
        • Celestia Points Booster
        • 🥛milkTIA x Demex Points Booster Bonanza
        • BTCETH Points Booster
        • 🟠 Archway Trading League
        • ⚛️ Cosmos Trading Competition
          • 🐋Whalecome to Demex
        • 💯DeFi & FOMO Points Booster
        • 💯DeFi & Layer 1 Points Booster
        • 💧dATOM Lend and Trade Spins Promo
        • 🐸Perp Pool Incentives with Leap Wallet
        • 👋Welcome #BackToDemex
        • 🥛milkTIA Lend and Trade Spins Promo
        • 🛡️Loss Protection
        • 🏃‍♂️STRD Lend and Trade Spins Promo
        • 🐶Meme Traders Arena
        • 🛡️Loss Protection Oct-Nov
        • 🌙LUNA Lend and Trade Spins Promo
        • 💯Modular Pool Points Booster
        • 🕰️Mantle Lend & Trade Spins Promo
        • 🏎️Mantle Trading League
        • 🛡️Loss Protection Dec 9 - 20
        • 👑Mantle Trading League S2
      • 2025
        • 🔲Mantle Rewards Station: 30,000,000 Demex Points
        • 🔲Mantle Rush
        • 🔐Loss Protection March 19 - 26, 2025
        • 🌀Mantle Lend & Trade Spins Promo
        • 💙Base Trading League
        • 🧢Base Lend & Trade Spins Promo
        • 🛡️Loss Protection Feb 10 - 20, 2025
        • 📝#DemexContentQuest
        • 📈#PerpsOnDemex
        • 👥Demex Referral Club
        • 🤖Traḋemex Bot
  • 📊Trade
    • Features
    • Perps & Futures
      • Pricing Engine
      • Margin Specifications
      • Liquidation Engine
      • Market Specifications
      • Pre-launch Perpetuals
      • Glossary
      • FAQs
    • Grouped USD Token
      • Constituent Criteria
      • Safety Features
      • Migration Guide
    • Fees
      • Trading Fees
      • Funding Fees
      • Network Fees
      • Deposit & Withdrawal Fees
      • Fee Delegation
      • CEX to Demex VIP Program
      • Fee Distribution
    • Notifications
      • Demex Progressive Web App (PWA)
    • Trading Modes
      • Lite Mode
      • Pro Mode
        • Features
        • Market Leverage
        • Order Types
        • Execution Options
        • Time-In-Force 🆕
        • Trigger (Stop) Orders
          • Take-Profit
          • Stop-Loss
        • Chart Trading 🆕
  • 💰EARN
    • Liquidity Pools
      • Spot Pools
        • Earnings
        • Amplified Pools
        • Uneven Pool Weights
        • Multi-Pool Routing
        • FAQs
      • Perp Pools
        • Earnings
        • Deposting & Redeeming
        • AMM Strategy
    • Nitron (Lend & Borrow)
      • Lending
      • Borrowing
        • Avoiding Liquidations
      • Liquidation
        • Partial Liquidations
      • USC Stablecoin
        • Interest Rate Model
      • High Efficiency Mode (E-Mode)
      • Liquidations
        • Liquidation Guide
      • Strategies
        • Using Nitron for Perp Trading
      • Protocol Safety Features
      • Risks
    • Referrals
      • Sharing Your Referral Link
      • FAQs
      • Terms and Conditions
  • Stake SWTH / DMX
  • 🫂COMMUNITY
    • Public Community Nodes
    • Feedback
    • Glossary
      • Annual Percentage Rate (APR)
      • Arbitrage
      • Decentralized Applications
      • Execution Options
      • Liquidation
      • Liquidity Pool
      • Liquidity Providers
      • Perpetual Pool
      • Open Interest (OI)
      • Order Book
      • Time-In-Force
      • Volume
      • Yield Farming
  • ⚙️Developers
    • APIs Overview
    • WebSocket API
    • RPC API
    • EVM API
    • Insights API
    • Node CLI
    • Running a Node
      • Testnet
      • Mainnet
      • Public API Node
      • Validators
        • Commissions & Penalties
  • 🤖EVM
    • Overview
    • Deployment Tutorial
    • Interacting with Demex L1
      • Built-in Oracle Contracts
      • Precompiled Trading Contracts
    • ICS-20 <> ERC-20 Token Conversion
    • Explorers
Powered by GitBook
On this page
  • Overview
  • What You'll Need
  • Deploying an EVM Contract

Was this helpful?

  1. EVM

Deployment Tutorial

PreviousOverviewNextInteracting with Demex L1

Last updated 2 months ago

Was this helpful?

Overview

In this getting started tutorial, you will deploy a sample contract within Demex's EVM module.

What You'll Need

  • Solidity Language Knowledge: For this guide, you write the smart contract code in Solidity programming language. Solidity is the primary programming language employed in Ethereum - designed specifically for writing smart contracts. This code will define the rules and logic of the smart contract, specifying how it will function and interact with the Demex network.

  • A Demex account: You will need a Demex account to deploy the smart contract. The account will hold the necessary funds to pay for the gas fees required for the deployment.

  • Sufficient funds: Deploying a smart contract on the Ethereum network requires paying transaction fees, also known as gas fees. The fees are payable in Ether (ETH), the native cryptocurrency of the Ethereum network. You must have sufficient funds in your Ethereum account to cover the transaction fees.

  • A deployment script or plugin: You will need deployment tools like HardHat or Truffle, to deploy the smart contract on Demex EVM. These tools will enable you to interact with the Demex network and execute the smart contract deployment transaction.

  • Access to a Demex node, either by running your own, connecting to a public node, or via an API key using a node service.

Deploying an EVM Contract

To deploy a Solidity Smart Contract via HardHat, you can follow these steps:

Step 1: Set up the development environment. Make sure to install the following prerequisites before setting up the project:

Step 2: Create a new project via npm init --y.

Step 3: Install hardhat dependencies required for the deployment via npm install --save-dev hardhat and npm install @nomicfoundation/hardhat-toolbox.

Step 4: Create a new hardhat project by running npx hardhat in your project directory. Ensure that the Create an empty hardhat.config.js option is selected.

Step 5: Create or insert your smart contract in the contracts directory. In this example, we will be using a sample ERC20 contract, named ERC20Token.sol.

Sample contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol
interface IERC20 {
    function totalSupply() external view returns (uint);

    function balanceOf(address account) external view returns (uint);

    function transfer(address recipient, uint amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}

contract ERC20 is IERC20 {
    uint public totalSupply;
    mapping(address => uint) public balanceOf;
    mapping(address => mapping(address => uint)) public allowance;
    string public name = "Solidity by Example";
    string public symbol = "SOLBYEX";
    uint8 public decimals = 18;

    function transfer(address recipient, uint amount) external returns (bool) {
        balanceOf[msg.sender] -= amount;
        balanceOf[recipient] += amount;
        emit Transfer(msg.sender, recipient, amount);
        return true;
    }

    function approve(address spender, uint amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    function transferFrom(
        address sender,
        address recipient,
        uint amount
    ) external returns (bool) {
        allowance[sender][msg.sender] -= amount;
        balanceOf[sender] -= amount;
        balanceOf[recipient] += amount;
        emit Transfer(sender, recipient, amount);
        return true;
    }

    function mint(uint amount) external {
        balanceOf[msg.sender] += amount;
        totalSupply += amount;
        emit Transfer(address(0), msg.sender, amount);
    }

    function burn(uint amount) external {
        balanceOf[msg.sender] -= amount;
        totalSupply -= amount;
        emit Transfer(msg.sender, address(0), amount);
    }
}

Step 6: Create a deploy.js script to deploy your contract under the scripts directory.

const { ethers } = require("hardhat");

async function main() {

  const [deployer] = await ethers.getSigners();
       
  console.log("Deployer ", deployer.address);

  const balance = await deployer.getBalance();

  console.log("Balance ", balance);

  const Token = await ethers.getContractFactory("ERC20");
  const token = await Token.deploy();

  console.log("Token address: ", token.address);
}

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

Step 7: Configure HardHat to use the Demex EVM via hardhat.config.js.

/** @type import('hardhat/config').HardhatUserConfig */
require('@nomicfoundation/hardhat-toolbox')
module.exports = {
  solidity: '0.8.18',
  networks: {
    testnet: {
      url: 'https://test-evm-api.carbon.network/',
      accounts: [YOUR_PRIVATE_KEY],
    },
  },
}

Ensure that your private key is inserted into accounts before running the next step.

Step 8: Deploy your contract by running npx hardhat run --network testnet scripts/deploy.js.

In this example, we are deploying to the testnet environment. The name of the environment should be the same as the one defined under networks in hardhat.config.js.

Step 9: If everything is working correctly, you should observe the corresponding logs being displayed on the console without any further errors.

Sample logs:

Deployer  0x5161e15Fee8b918d4621703dB75641BbC25301c8
Balance  BigNumber { value: "12333000000000000000000" }
Token address:  0x112601CcF79eF9D634B45ABC972e2863e595569e

Congratulations, you’ve successfully deployed your first smart contract on Demex EVM!

Introduction

In this getting started tutorial, you will deploy a sample contract within Demex's EVM module.

What You'll Need

  • Solidity Language Knowledge: For this guide, you write the smart contract code in Solidity programming language. Solidity is the primary programming language employed in Ethereum - designed specifically for writing smart contracts. This code will define the rules and logic of the smart contract, specifying how it will function and interact with the Demex network.

  • A Demex account: You will need a Demex account to deploy the smart contract. The account will hold the necessary funds to pay for the gas fees required for the deployment.

  • Sufficient funds: Deploying a smart contract on the Ethereum network requires paying transaction fees, also known as gas fees. The fees are payable in Ether (ETH), the native cryptocurrency of the Ethereum network. You must have sufficient funds in your Ethereum account to cover the transaction fees.

  • A deployment script or plugin: You will need deployment tools like HardHat or Truffle, to deploy the smart contract on Demex EVM. These tools will enable you to interact with the Demex network and execute the smart contract deployment transaction.

  • Access to a Demex node, either by running your own, connecting to a public node, or via an API key using a node service.

Guide

To deploy a Solidity Smart Contract via HardHat, you can follow these steps:

Step 1: Set up the development environment. Make sure to install the following prerequisites before setting up the project:

Step 2: Create a new project via npm init --y.

Step 3: Install hardhat dependencies required for the deployment via npm install --save-dev hardhat and npm install @nomicfoundation/hardhat-toolbox.

Step 4: Create a new hardhat project by running npx hardhat in your project directory. Ensure that the Create an empty hardhat.config.js option is selected.

Step 5: Create or insert your smart contract in the contracts directory. In this example, we will be using a sample ERC20 contract, named ERC20Token.sol.

Sample contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol
interface IERC20 {
    function totalSupply() external view returns (uint);

    function balanceOf(address account) external view returns (uint);

    function transfer(address recipient, uint amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}

contract ERC20 is IERC20 {
    uint public totalSupply;
    mapping(address => uint) public balanceOf;
    mapping(address => mapping(address => uint)) public allowance;
    string public name = "Solidity by Example";
    string public symbol = "SOLBYEX";
    uint8 public decimals = 18;

    function transfer(address recipient, uint amount) external returns (bool) {
        balanceOf[msg.sender] -= amount;
        balanceOf[recipient] += amount;
        emit Transfer(msg.sender, recipient, amount);
        return true;
    }

    function approve(address spender, uint amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    function transferFrom(
        address sender,
        address recipient,
        uint amount
    ) external returns (bool) {
        allowance[sender][msg.sender] -= amount;
        balanceOf[sender] -= amount;
        balanceOf[recipient] += amount;
        emit Transfer(sender, recipient, amount);
        return true;
    }

    function mint(uint amount) external {
        balanceOf[msg.sender] += amount;
        totalSupply += amount;
        emit Transfer(address(0), msg.sender, amount);
    }

    function burn(uint amount) external {
        balanceOf[msg.sender] -= amount;
        totalSupply -= amount;
        emit Transfer(msg.sender, address(0), amount);
    }
}

Step 6: Create a deploy.js script to deploy your contract under the scripts directory.

const { ethers } = require("hardhat");

async function main() {

  const [deployer] = await ethers.getSigners();
       
  console.log("Deployer ", deployer.address);

  const balance = await deployer.getBalance();

  console.log("Balance ", balance);

  const Token = await ethers.getContractFactory("ERC20");
  const token = await Token.deploy();

  console.log("Token address: ", token.address);
}

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

Step 7: Configure HardHat to use the Demex EVM via hardhat.config.js.

/** @type import('hardhat/config').HardhatUserConfig */
require('@nomicfoundation/hardhat-toolbox')
module.exports = {
  solidity: '0.8.18',
  networks: {
    testnet: {
      url: 'https://test-evm-api.carbon.network/',
      accounts: [YOUR_PRIVATE_KEY],
    },
  },
}

Ensure that your private key is inserted into accounts before running the next step.

Step 8: Deploy your contract by running npx hardhat run --network testnet scripts/deploy.js.

In this example, we are deploying to the testnet environment. The name of the environment should be the same as the one defined under networks in hardhat.config.js.

Step 9: If everything is working correctly, you should observe the corresponding logs being displayed on the console without any further errors.

Sample logs:

Deployer  0x5161e15Fee8b918d4621703dB75641BbC25301c8
Balance  BigNumber { value: "12333000000000000000000" }
Token address:  0x112601CcF79eF9D634B45ABC972e2863e595569e

Congratulations, you’ve successfully deployed your first smart contract on Demex EVM!

🤖
Node.js & npm(7 and above)
Git
Node.js & npm(7 and above)
Git