December 22, 2024

Deploying a contract to the Mezo testnet using Remix

Deploying contracts is sometimes necessary for retroactive activities. In this article, I will explain how to do this in the Mezo testnet using a simple ERC-20 token as an example.

1. First, we need Mats in Mezo, if you have already staked them in mezo.org/matsnet as required in the previous guide https://teletype.in/@coingonzo/mezo_testnet , then proceed to the next step

2. Add the network to the EVM wallet: https://chainlist.org/chain/31611
We will see BTC - these are our mats, which we will use for gas

3. Go here https://remix.ethereum.org/ and select the ERC-20 contract

4. In the contract files we find "MyToken.sol", erase everything from there and paste this there:

Change "CoinGonzo" and "GNZ"on your names

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

contract CoinGonzo { // Token details string public name = "CoinGonzo"; string public symbol = "GNZ"; uint8 public decimals = 18; uint256 public totalSupply;

// Balances for each account mapping(address => uint256) public balanceOf; // Allowances for spending mapping(address => mapping(address => uint256)) public allowance;

// Events event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value);

// Constructor constructor(uint256 initialSupply) { totalSupply = initialSupply * (10 ** decimals); // Scale the supply based on decimals balanceOf[msg.sender] = totalSupply; // Assign the entire supply to the deployer emit Transfer(address(0), msg.sender, totalSupply); }

// Transfer function function transfer(address to, uint256 value) public returns (bool success) { require(to != address(0), "Invalid address"); require(balanceOf[msg.sender] >= value, "Insufficient balance");

balanceOf[msg.sender] -= value; balanceOf[to] += value; emit Transfer(msg.sender, to, value); return true; }

// Approve allowance function approve(address spender, uint256 value) public returns (bool success) { require(spender != address(0), "Invalid address");

allowance[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; }

// Transfer from (for allowances) function transferFrom(address from, address to, uint256 value) public returns (bool success) { require(to != address(0), "Invalid address"); require(balanceOf[from] >= value, "Insufficient balance"); require(allowance[from][msg.sender] >= value, "Allowance exceeded");

balanceOf[from] -= value; balanceOf[to] += value; allowance[from][msg.sender] -= value; emit Transfer(from, to, value); return true; } }

5. In the Solidity Compiler tab:
- Select the Compiler version 0.8.20 commit
- Click Advanced Configuration and select EVM VERSION - london

6. In the Deploy & run tab:
-In Environment, select Inject Provider - Metamask (If you are using another wallet, then click Custom this list and add the option you need for your wallet. For example: "Injected Provider - OKX Wallet" to do this via OKX)

- Next to the orange Deploy button, enter the desired number of tokens and click on this button, then sign the transaction

7. A green check mark will appear at the bottom. Open it and find the contract address, copy it and import the token into your wallet.

Adding a token for those who don't know:

Done, now you can send your token in the Mezo testnet! I think this activity will not go unnoticed by the drop checker)

https://t.me/coingonzo - Subscribe to learn about fresh activities in the testnet