How to Create and Deploy an ERC20 Token – In 20 minutes

Recently, cryptocurrencies have gained popularity, providing businesses, individuals, and DAOs with countless opportunities. 

That’s the place to go if you want to find out how to create and use an ERC20 token in under twenty minutes.

This tutorial will teach you how to use Solidity and the OpenZeppelin-maintained to Create ERC20 Token standard (Ethereum request of comment) to create a cryptocurrency.

First, we will use the online REMIX IDE, designed especially for Ethereum development with Solidity, to write the Smart Contract. Then, in order to launch your own cryptocurrency on the Mumbai Polygon Testnet, we’ll set up a local environment using Hardhat.

By the end of this tutorial you’ll learn:

  • How to Create and Deploy ERC20 Token: what is an ERC20
  • How to Create and Deploy an ERC20 Token
  • How to Use Mint to Create an ERC20 Token The Digital Money
  • Deploy Your ERC20 Token Cryptocurrency
  • Conclusion

It is not assumed any previous Solidity knowledge, although it is suggested to have some previous programming knowledge before starting this tutorial. I strongly recommend that you go check out the entire web3 roadmap (updated this year) if you’re not sure where to begin.

Having said that, let’s get right to creating and implementing an ERC20 token.

How To Create an ERC20 Token: Set up The Environment With REMIX

We’ll learn how to use REMIX, an intuitive, free IDE that has decent compile-time errors and a great Solidity compatibility feature, to create and deploy an ERC20 Token Smart Contract.

Open the contacts folder by going to remix.ethereum.org, then create a new file named “Token.sol”:

In order to tell the compiler which version of Solidity to use when building our code, the License-identifier and the pragma must be added to every new Solidity file.

Put this code in the Token.sol file:

Token.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

Because of the double quote (\”), the code works with Solidity 0.8.0 through 0.89 versions of the compiler.

Let me quickly go over what an ERC20 token development is as it’s crucial to understand if you want to create your own cryptocurrency. Next, we need to import the ERC20 token contract from OpenZeppelin.

How to Create and Deploy ERC20 Token: what is an ERC20

According to the official OpenZeppelin documentation:

An ERC20 token contract keeps track of “tonicible tokens,” or tokens that are identical to one another and lack any distinguishing characteristics.As a result, ERC20 tokens are used for staking, voting, and other purposes, in addition to serving as a medium of exchange.”

In its most basic form, ERC20 is just a class that implements the members and methods of what are commonly known as cryptocurrencies. This term has a wider meaning, though, because ERC20 finds use in other contexts.

Conversely, OpenZeppelin is regarded as the industry standard library for ERC contracts classes.

How to Create and Deploy an ERC20 Token

Import the OpenZeppelin ERC20 contract in the Token.sol file:

Token.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

Additionally, initialize the token by importing the ERC20.sol contract:

Token.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

contract DevToken is ERC20{

}

Here, we’re using the Solidity keyword contract to declare a new contract called “DevToken” and the “is’ keyword to inherit from the ERC20 OpenZeppelin contract.

By inheriting from the ERC20 contract, we will have access to functions such as balanceOf() and _mint(). You can use the official ERC20 documentation to browse through all of the available techniques.

The next step in creating a cryptocurrency is to call the constructor of the contract and supply the token’s name and symbol. To accomplish this, place the following code inside the contract:

Token.sol

contract DevToken is ERC20{

    constructor() ERC20(“DevToken”, “DVT”){

    }

}

Your code should now appear like this:

Token.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

contract DevToken is ERC20{

    constructor() ERC20(“DevToken”, “DVT”){

    }

}

 

Great! We now have one final task to complete before testing our own cryptocurrency and going on to more difficult subjects: successfully deploying our ERC20 token.

How to Use Mint to Create an ERC20 Token The Digital Money

As previously stated, we can access the _mint() method, which is exactly what we need right now, by inheriting from the ERC20 contract. This method allows us to create new tokens and send them to a specified address.

The process of verifying data, generating a new block, and entering that data into the blockchain is known as minting. To put it simply, “minting” is the process of creating an NFT or a number of tokens and storing them on the blockchain.

Suppose we wish to generate a thousand tokens and transfer them to our wallet. We can accomplish this by including the subsequent code in the constructor:

First of all, we’re calling the _mint() function, which is responsible to issue the tokens, and wants two parameters:

  • to: the contract’s address or wallet where the tokens will be received,
  • amount: amount of tokens to send.

The “to” argument is taken from msg.sender, a special variable whose value is the address of the wallet/contract calling the contract. However, the amount must account for the decimals, which is why we are passing such a large amount. Allow me to go over it briefly.

A Note On Decimals

You might want to be able to send any amount, such as 0.004ETH, when working with cryptocurrencies. Regretfully, decimals are not supported by Solidity or the Ethereum Virtual Machine; only integer numbers are. This means that only whole numbers (1, 4, 5, etc.) can be sent, which naturally presents a problem.

So what’s the workaround?

It’s very easy to understand; a token contract can use larger integer values (the EVM supports 256-bit integers), so a transfer of 4000000000000000 will correspond to 0.004ETH being sent. One ETH is represented by a balance of 1000000000000000000 with 18 decimal places.

With that in mind, when calculating our total supply, we have to take account of the total amount of tokens, including the decimal places we want to have.

To achieve the 1.000.000.000 token maximum supply with 18 decimal places, as Ethereum and several other cryptocurrencies do, you must pass 1000000000*10**18, or 1000000000000000000000000000.

However, the call method when sending two tokens will be as follows:

  • transfer(recipient, 2 * 10**18);

We can now test our ERC20 Token contract since we have a better understanding of what is happening in the mint function.

 

Deploy Your ERC20 Token Cryptocurrency

Select the Solidity icon located on the left side of the screen on REMIX, then select Compile. In order to enable REMIX to compile your code and listen for code changes, you might also want to enable auto compile.

In order to deploy the Token on the blockchain, this will compile the Token.sol code and add our Token’s Contract abi (application binary interface) and their binary version to the artifacts folder.

Once our artifacts are ready, click the Ethereum logo beneath the Solidity icon, choose your contract from the drop-down menu, and then click “deploy”:

In order to deploy the Token on the blockchain, this will compile the Token.sol code and add our Token’s Contract abi (application binary interface) and their binary version to the artifacts folder.

Once our artifacts are ready, click the Ethereum logo beneath the Solidity icon, choose your contract from the drop-down menu, and then click “deploy”:

How to Develop a ERC20 token : Create A Token Supply That Works

At the point when you really want to make your own digital money supply, we have 3 primary options:

  • Fixed Supply
  • Uncapped Languid Inventory
  • Covered Languid Inventory

As of now, our token has a Proper stockpile given on sending, we should investigate what it implies, and the choices we have while fostering our cryptographic forms of money.

Fixed Supply

The complete stock of the token is given on organization and shipped off the sending wallet address.

For this situation, we pick an all out supply ahead of time and issue the entire add up to our wallet when the agreement’s constructor gets called, leaving us the work of disseminating the tokens among various holders.

To give every one of the tokens on the double, however, we ought to choose a sluggish printing approach.

Uncapped Languid Inventory

Tokens aren’t printed and given in an exceptional cluster on sending, yet in little amounts and shipped off the predefined wallet(s), thusly to at least one activities.

For this situation, the complete max supply is directed through monetary driven standards and not on a hard-coded esteem.

Consider a Digger approving an exchange and getting tokens back as a prize, or a client stacking their tokens to get intermittent prizes.

The shortfall of a hardcoded Max supply, however, could make your token inflationary, causing a deficiency of significant worth over the long haul, or most terribly seriously jeopardizing its security. Regardless of whether this goes outside the focal point of this instructional exercise, it is great to comprehend that we can, and ought to, cap our stock.

Covered Apathetic Stockpile

Like in the Uncapped Apathetic Stockpile system, the tokens are given in little amounts, with the main contrast that here the maximum inventory is chosen ahead of time and hardcoded in the savvy contract, or passed on sending.

In this instructional exercise, we will extensively investigate every one of the strategies to make the stockpile of our Tokens.

Coclusion : 

Congratulations! You’ve just used cryptocurrency for the first time!

I sincerely hope you understand how to generate and use an ERC20 token! If you run into any problems.

Guest article written by: Ragunath.T is a Digital Marketing Executive at ERC20 Token development company .He designs marketing strategies with the intention of using high-quality content to educate and engage audiences. His specialties include social media marketing specialist, SEO, and he works closely with B2B and B2C businesses, providing digital marketing strategies that gain social media attention and increase your search engine.