If you read this article, you know how to deploy a very simple contract on evm chains. the contract you deployed has no efficiency and do nothing. Let’s think and do more complex. In this tutorial we will learn to deploy and interact (send, approve, burn…) with a token contract, that makes more sense.
Let’s jump into the process, but before that make sure to read the previous article carefully. Open remix, create a “.sol” file and copy and paste the code below:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract ERC20Token is ERC20 {
uint8 private decimal;
constructor(string memory _name, string memory _symbol, uint256 totalSupply, uint8 _decimal) ERC20(_name, _symbol){
_mint(msg.sender, totalSupply * 10 ** _decimal);
decimal = _decimal;
}
function decimals() public view virtual override returns (uint8) {
return decimal;
}
function burn(uint256 amount) public virtual returns (bool) {
address owner = _msgSender();
_burn(owner, amount);
return true;
}
}
After that, compile the code, connect your wallet and get ready to deploy it (steps 4 and 5 in the prev. article). The next steps are a little different. Expand “Deploy” item by clicking on the arrow next to it, as shown below:
Now you should see four fields:
Fill in the fields as explained below:
_NAME: Choose a name for your token (e.g. Ethereum, Polygon)
_SYMBOL: Choose a symbol for your token (e.g. ETH, MATIC)
TOTALSUPPLY: Specify the total supply of your token. No need to enter decimals. (e.g. 21000000 for BTC)
_DECIMAL: Decimals for your token. Most of ERC20 tokens have 18 decimals. You can choose any number from 0 to 255.
Then click on “transact” button and confirm the message in your wallet.
**This token has no value, so just try it on test networks.
Now it’s time to interact with your contract. From “Deployed Contracts” section choose your contract and expand it:
There are two types of buttons. The blue buttons are read-only and do not change the state of the blockchain, and no need to pay gas. You can get the token balance of an address, or check the total supply, name and symbol of your token (The zeros you see are decimals). Feel free to click on them. The orange buttons are what we need to interact with our contract:
Expand “transfer” button, enter the destination address in “to” field, and amount of tokens you want to transfer in “amount” field (all tokens you minted are in your wallet as the owner. you can check your wallet balance by “balanceOf” blue button). Click on “transact” and confirm from your wallet. Congrats, you made the first transaction by your contract. Other buttons have a similar functionality. you can burn, change the allowance of a wallet or approve to spend tokens. Since you do not pay real money, I leave it to you to test the rest of the buttons.
Note:
This tutorial does not guarantee any reward or drop, so do it if you want to help to test new networks.
You can do it as many as you want on different chains.
It is not recommended to try on mainnet chains.