1. Home
  2. Docs
  3. Nexi Docs
  4. Token creation and manage...
  5. Deploy a token (ERC-20 compatible)

Deploy a token (ERC-20 compatible)

1. Set Up Your Development Environment

  1. Install MetaMask:
    • Ensure you have MetaMask installed and configured to connect to the Nexi chain. Follow the instructions in the previous response if needed.
  2. Access Remix IDE:

2. Write Your ERC20 Token Contract

  1. Create a New Solidity File:
    • In Remix, go to the File Explorer panel.
    • Click on the New File icon and name your file (e.g., MyToken.sol).
  2. Write the ERC20 Token Contract:
    • Copy and paste the following Solidity code into your new file. This code creates a simple ERC20 token contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

// Function to mint new tokens, only accessible by the owner
function mint(address to, uint256 amount) external onlyOwner {
_mint(to, amount);
}

// Function to burn tokens from the owner's balance
function burn(uint256 amount) external onlyOwner {
_burn(msg.sender, amount);
}
}
  • This contract uses the OpenZeppelin library for the ERC20 standard and ownership control.

3. Compile the Contract

  1. Select Compiler Version:
    • Go to the Solidity Compiler tab in Remix (left sidebar).
    • Choose the Solidity version that matches your contract (e.g., 0.8.0).
  2. Compile the Contract:
    • Click “Compile MyToken.sol” to compile the contract.

4. Deploy the Contract on the Nexi Chain

  1. Configure Remix to Use MetaMask:
    • Go to the Deploy & Run Transactions tab in Remix.
    • Set the Environment to “Injected Web3”. MetaMask should automatically connect to the Nexi chain.
  2. Deploy the Contract:
    • Select your contract (MyToken) from the dropdown menu.
    • Enter the initial supply for your token in the “initialSupply” field (e.g., 1000000).
    • Click “Deploy” and confirm the transaction in MetaMask.
  3. Confirm Deployment:
    • Once deployed, the contract address will appear under “Deployed Contracts” in Remix. You can interact with the contract from this section.

5. Interact with Your Token

  1. Verify Token Deployment:
    • Use a block explorer (if available) to verify that your contract has been deployed on the Nexi chain.
  2. Test Token Functions:
    • Use Remix’s interface to interact with your contract’s functions (e.g., mint, burn, balanceOf, etc.).
  3. Integrate with dApps:
    • You can now integrate your token with decentralized applications or use it in your projects on the Nexi chain.