LogoLogo
WalletsEcosystemStart BuildingJoin the Community
  • Welcome to IoTeX 2.0
    • 💡Why IoTeX
    • 🪙Tokenomics
      • IOTX Utility in IoTeX 2.0
      • IOTX Emission, Deflation, and Re-Staking
    • 📖Whitepaper
    • ⚡Get Started
  • DePIN Infra Modules (DIM)
    • DIMs Overview
    • [IoTeX L1] DePIN Blockchain
      • Core Concepts
        • Consensus Mechanism
        • Voters and Delegates
        • Ethereum Virtual Machine
        • Accounts & Identities
        • Blockchain Actions
        • ERC20 and NFT Tokens
        • Smart Contracts
        • Interoperability
        • Governance
      • The IOTX Token
        • IOTX Token Exchange Support
        • Different Formats of the IOTX Token
        • IOTX Token Contracts
      • Wallets
        • Supported Wallet Apps
          • ioPay Mobile
          • IoTeX Web Wallet
          • OKX Wallet
          • Rabby Wallet
          • Metamask Desktop
          • Ledger Nano S & X
            • Use Ledger with Metamask
            • Use Ledger with Rabby Walet
            • Use Ledger with IoTeX Hub Portal
            • Migrate to the Ethereum Ledger App
          • IoTeX Desktop Wallet
          • 👩‍💻IoTeX HD Derivation Path
        • Buy IOTX Tokens
        • Execute Transactions
          • Transfer IOTX Tokens
          • Transfer ERC20 Tokens
          • Interact with Dapps
          • Explore transactions
        • Migrate Assets to a different wallet
      • Staking & Governance
        • About IoTeX Staking
        • IoTeX Staking Guide
          • Native staking
          • Staking as NFT
        • Join the Governance
          • Marshall DAO
          • Improvement Proposals
      • Exchange Integration
      • 👨‍💻Deploy Dapps on IoTeX
    • [ioID] DePIN Identities
      • Why ioID?
      • System Architecture
      • Technical Specification
      • API Overview
      • ioID Enabled Services
      • Integrating ioID
      • Example Use Cases
    • [W3bstream] DePIN Verification
      • Overview of W3bstream
      • Multi-Prover Architecture
      • 👨‍💻Build with W3bstream
        • Get Started
          • Sequencer Options
        • Build the Prover Code
          • Risc Zero
          • Halo2
          • zkWASM
        • Deploy to W3bstream
          • Create the Project File
          • W3bstream Outputs
          • Deploying Projects
          • Interacting with Projects
        • On-chain integration
          • Verify Risc0 Proofs
          • Verify Halo2 Proofs
          • Verify zkWASM profs
        • Sending Messages
      • 👩‍💻Node Operators
        • Configure a ZK Prover Node
        • Register your Node
    • [ioID-SDK] Hardware SDK
      • ioID-SDK Overview
      • Layered Architecture
      • Compatibility
      • Current Development Status
    • [MSP] Modular Security Pool
    • Third-Party DIMs
      • Data Sequencer Infras
      • Data Availability Infras
      • 👨‍💻W3bstream Tasks
  • Ecosystem
    • Assets on IoTeX
      • Mainstream Assets
      • IOTX and Derivatives
      • DePIN Tokens
      • MEME Coins
    • iotube Bridge
    • iotexscan Explorer
    • Ecosystem Apps
      • DePINScan
      • mimo DEX
      • ecosystem.iotex.io
    • "Powered by IoTeX" Devices
      • Pebble Tracker
        • Quick Start
        • Device Registration
        • Online Firmware Update
        • USB Firmware Update
        • Migrating to Pebble v2.0
          • 1.0 Device Registration
        • Tech Specs
        • Network Selection
        • Pebble Configuration
        • Query Pebble Data
        • Troubleshooting
        • Firmware Development
          • Hardware Setup
          • Build the Firmware
          • Flash the firmware
      • SenseCAP Indicator
      • UCam Home Camera
  • Builders
    • IoTeX Developer Portal
    • Dev Chat on Discord
    • Web3 Development
      • RPC Endpoints
      • Set up your Environment
      • Get Testnet IOTX Tokens
      • ioctl CLI
        • Installation
        • Create Accounts
        • Blockchain interaction
          • ioctl command reference
      • Chain Indexing
        • The Graph
        • SubQuery
        • IoTeX Analytics API
      • IoTeXscan API
      • Deterministic Deployment
      • Account Abstraction
        • Components of AA
        • 👩‍💻Creating new Accounts
        • 👨‍💻P256Account Example
      • Blob Transactions (EIP-4844)
      • Multicall3
      • EVM Precompiled Contracts
    • Building DePINs
      • ioID Step by Step Tutorial
        • Integrate ioID in the Device Firmware
        • Integrate ioID in your cloud
      • Decentralized WiFi Connectivity (DeWi)
        • Project Specification
        • The choice of Hardware
        • The Data API Service
        • DePIN Incentives Contract
    • Building DeFi
      • Deploy Tokens
        • Deploy an ERC20 Token
        • Deploy an NFT Token
      • Price Oracles
        • Chainlink Relayer
        • SupraOracles
      • Integrate IoTeX Staking
      • Liquid staking Dapps
    • Launch Dapps on IoTeX
      • Submit Tokens to the IoTeX Ecosystem
      • Submit tokens to the iotube bridge
      • Verify Smart Contracts
      • Audit your Contracts
      • Submit your Dapp to Portals
      • Useful tools
    • Node Operators
      • Fastblocks (Node as a Service)
      • Setup an IoTeX RPC Node
      • Run a Delegate Node
      • Rosetta API
    • Reference Docs
      • ioctl client
        • Accounts
        • HD Wallets
        • Aliases
        • Actions
        • Queries
        • Smart Contracts
        • Staking & Voting
        • Tokens
        • ioID Identities
        • W3bstream
        • Decentralized Identifiers (DID)
        • JWT Auth Tokens
      • Native IoTeX Development
        • IoTeX gRPC API
        • Account Cryptography
        • Address Conversion
        • Create Accounts
        • Estimate Gas Price
        • Make IOTX Transfers
        • Manage ERC20 Tokens
        • Smart Contract Interactions
        • ioPay Desktop
        • DID JWT Tokens
        • Calling any RPC method
      • Embedded Blockchain Clients
        • Arduino IDE
        • Linux Systems
        • PlatformIO
        • Examples
        • Tutorials
  • Participate
    • Crypto's Got Talent (CGT)
      • IoTeX x Polygon DePIN Grant
    • Governance
      • IoTeX Improvement Proposals
      • The Marshall DAO
    • Join the Community
    • Get in Touch
Powered by GitBook
LogoLogo

This documentation portal is currently undergoing updates to align with the IoTeX 2.0 Whitepaper release. Information provided here may be incomplete, or out-of-date. Please use this portal for preliminary reference only, and check out the official IoTeX 2.0 Whitepaper for updated information.

  • .

2025 | IoTeX

On this page
  • Example contract
  • Code Explanation
  • Deploy using Hardhat
  • Set up the environment
  • Install dependencies & Hardhat plugins
  • Update Hardhat Config
  • Create the Contract File
  • Write an ignition module for Deployment
  • Deploy the Contract
  • Deploy using Foundry
  • Setup the Environment
  • Set Up Your Project
  • Write Your Smart Contract
  • Compile Your Smart Contract
  • Configure a Deployment Script
  • Deploy Your Smart Contract
  • Verify the Deployment
  • Example Contract Interaction

Was this helpful?

Export as PDF
  1. Builders
  2. Building DeFi
  3. Deploy Tokens

Deploy an ERC20 Token

Example contract

Let's start with a simple ERC20 token an example contract:

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

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

contract ExampleToken is ERC20, Ownable {
    constructor() ERC20("ExampleToken", "ETK") Ownable(msg.sender) {
        _mint(msg.sender, 1000);
    }

    function mint(address to, uint256 amount) external onlyOwner {
        _mint(to, amount);
    }
}

Code Explanation

Constructor: The constructor initializes the token with a name ("ExampleToken") and symbol ("ETK"), and mints the initial supply to the contract deployer.

Mint Function: The mint function allows the owner (i.e. the account that deployed the contract) to mint additional tokens.

Deploy using Hardhat

Set up the environment

Ensure you have the latest nodeJS and npm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
nvm install 22
nvm use 22
nvm alias default 22
npm install npm --global # Upgrade npm to the latest version

Create a new Hardhat project:

mkdir ExampleToken && cd ExampleTokem
npm init
npm install --save-dev hardhat
npx hardhat init

Install dependencies & Hardhat plugins

npm install @openzeppelin/contracts
npm install --save-dev @nomicfoundation/hardhat-toolbox

Update Hardhat Config

Open hardhat.config.js and configure the IoTeX network:

javascript
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.20",
  networks: {
    testnet: {
      url: "https://babel-api.testnet.iotex.io",
      accounts: [`${TESTNET_PRIVATE_KEY}`]
    },
    mainnet: {
      url: "https://babel-api.testnet.iotex.io",
      accounts: [`${MAINNET_PRIVATE_KEY}`]
    }
  }
};

Replace TESTNET_PRIVATE_KEY with the private key of the account you want to use for deployment.

Create the Contract File

Write an ignition module for Deployment

Inside the ignition folder add a file ExampleToken.js with the following content:

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
const { parseUnits } = require("ethers"); // Ensure you import parseUnits from ethers

const ExampleTokenModule = buildModule("ExampleTokenModule", (m) => {

  // Deploy the ExampleToken contract with the specified initial supply
  const token = m.contract("ExampleToken");

  return { token };
});

module.exports = ExampleTokenModule;

Deploy the Contract

npx hardhat ignition deploy ./ignition/modules/ExampleToken.js --network testnet

This setup should provide a comprehensive tutorial on deploying a basic ERC20 token contract on the IoTeX blockchain using HardHat.

Deploy using Foundry

This quick start guide will help you deploy smart contracts on the IoTeX blockchain using the Foundry suite. Foundry is a fast, portable, and modular toolkit for Ethereum application development written in Rust.

Setup the Environment

If you haven't installed Foundry, use the following command:

curl -L https://foundry.paradigm.xyz | bash foundryup

Set Up Your Project

Create a new project directory and navigate into it:

mkdir ExampleToken && cd ExampleToken

Initialize a new Foundry project:

forge init

Write Your Smart Contract

Compile Your Smart Contract

Compile the smart contract using Foundry:

forge build

Configure a Deployment Script

Foundry uses cast to interact with the blockchain. Create a .env file to store your private key securely:

echo "PRIVATE_KEY=your_private_key_here" > .env

Load the environment variables:

source .env

Deploy Your Smart Contract

Use the cast send command to deploy your contract to the IoTeX testnet. Replace MyContract with the name of your compiled contract and adjust the RPC URL if needed.

cast send --rpc-url https://babel-api.testnet.iotex.io \
  --private-key $PRIVATE_KEY --legacy --create \
  $(cat out/MyContract.sol/MyContract.json | jq -r .bytecode.object)

Verify the Deployment

Once deployed, you will receive a transaction hash. Use this hash to verify the deployment on the IoTeX testnet explorer.

Example Contract Interaction

After deployment, you can interact with your contract. For example, to call the setMessage function:

cast send --rpc-url https://babel-api.testnet.iotex.io \
  --private-key $PRIVATE_KEY --legacy \
  <contract_address> "setMessage(string)" "Hello, IoTeX!"

Conclusion

PreviousDeploy TokensNextDeploy an NFT Token

Last updated 6 months ago

Was this helpful?

Imports: The contract imports the ERC20 and Ownable contracts from .

Create a new contracts directory and new file contracts/ExampleToken.sol and add the ERC20 token contract code (make sure you delete any example contracts already created in the contracts folder).

Navigate to the src directory and create a new Solidity file ExampleToken.sol and add the ERC20 token contract code .

By following this quick start guide, you have successfully deployed a smart contract on the IoTeX blockchain using the Foundry suite. Foundry’s powerful tools make it easy to develop, deploy, and interact with smart contracts on IoTeX. For more advanced features and configurations, refer to the .

If you have any questions or run into issues, feel free to ask !

OpenZeppelin
-> Learn more about HardHat
-> Configure an IoTeX Wallet
→ Request test IOTX tokens
-> Learn more about Foundry
Foundry documentation
our community on Discord
provided above
provided above