Creating an ERC-20 Token

Creating an ERC-20 Token

Introduction

A mentor gave me an assignment at web3brigde to build an ERC-20 token. In this article, I will talk about how the contract works, and what the functions in the contract do.

What is an ERC-20 Token

ERC-20 is a specification or standard for creating and managing tokens on the Ethereum blockchain. Think of it like a set of rules or guidelines that developers follow to make sure their tokens can work smoothly with other tokens and applications on Ethereum Blockchain.

Creating Process

In this section, I'll be taking you through the simple process I followed when creating my ERC-20 Token.

Process 1. Setting Up

  • Opened my internet browser(Google Chrome)

  • I Opened the Remix Ethereum IDE using this link

  • After opening the remix platform I navigated into the contracts folder

  • And created a file named ERC20.sol

Process 2. Start Building

  • Inside the ERC20.sol file, I declared the SPDX-License-Identifier

  • I also declared the pragma solidity version

  • And then the contract keyword and the contract name

Process 3. State Variable Declaration

  • After declaring the contract keyword and name, I then declared my state variables

  • Line 5 holds the name of the token with the type of string

  • Line 7 holds the symbol of the token with the type of string

  • Line 9 holds the decimal that will be assigned to each token with the type of uint256

  • Line 11 holds the total amount of tokens that will be created

  • Line 13 keeps track of the address that created the token and the amount of token tied to that address

  • Line 15 keeps track of the owner's address, the spender's address, and the amount of token that has been approved to the sender's address

Process 4. Events and Constructor Declaration

  • After declaring my state variables, I moved on to declaring the events and constructor

  • Line 17 declares an event named Transfer with 3 parameters that represent the sender, receiver and the amount of token to be transferred

  • Line 19 declares an event named Approval with 3 parameters that represent the owner, spender, and the amount of token approved to the spender

  • Line 21 is a constructor with an argument that will require the _initialSupply(amount of tokens to be created)

  • Line 23 is a mathematical expression that calculates the total supply of tokens based on the _initialSupply and the number of decimal places specified by the decimals variable

  • Line 25 sets the balance of the contract deployer (the address that deploys the contract) to the total supply of tokens

Process 5. Creating the Transfer Logic Function

  • After the events and constructor declaration, I move on to creating the transferLogic function