Search
Generic filters
Share on facebook
Share on twitter
Share on linkedin

What are ERC20 Contracts? – Full ERC20 Contract Guide

By now, most people have heard of blockchains such as Ethereum. While Bitcoin was the first blockchain, the Ethereum chain was the first programmable blockchain. Furthermore, with its first-mover advantage and a strong community, Ethereum remains the most popular go-to chain for deploying dApps (decentralized applications). Plus, Ethereum’s blockchain also supports the greatest number of crypto tokens. Including some extremely reputable cryptocurrencies, such as LINK, ZRX, MKR, and BAT, which are all based on ERC20 contracts. Not sure what ERC20 contracts are? Do not worry; you’ll have a solid understanding of what an ERC20 contract is by the end of this article.

Moving forward, we’re first going to ensure that you all know what ERC20 smart contracts are. We’ll also explain smart contracts in general, including what they allow for. Then, we’ll show you how to create ERC20 tokens to deepen your understanding. By covering the overview of using ERC20 contracts, you’ll also get to see Moralis (a.k.a. Firebase for crypto) in action. You’ll learn how to use this ultimate Web3 development tool to help speed up all sorts of blockchain development tasks. Essentially, Moralis provides frontend developers with the power to create phenomenal dApps using JavaScript and MetaMask. Of course, besides frontend developers, numerous backend programmers are jumping aboard this “future-proof train”. So, if you are serious about becoming a blockchain developer, make sure to create your free Moralis account today.

What is an ERC20 Contract?

Despite the fact that blockchain technology has been around since 2009, it still hasn’t received mainstream adoption. But, we are slowly getting there; remember, “Slow is smooth and smooth is fast”. Moreover, by ensuring that as many people as possible have a clear understanding of the important underlying concepts, we will get there even faster. As such, let us first inform you that “contracts” in the crypto realm refer to “smart contracts”. These are basically computer programs or transaction protocols running on programmable blockchains. We’ll cover the details of smart contracts in the “Smart Contracts Explained” section below. With that in mind, let’s take a look at what an ERC20 contracts is, shall we.

What are ERC20 Smart Contracts?

“Ethereum Request for Comment 20”, or ERC20, was implemented back in 2015, the same year when the Ethereum chain saw the light of day. As such, the ERC20 standard was born. Moreover, note that all ERC20 smart contracts, or ERC20 contracts, are smart contracts that follow the ERC20 standard. As such, the real question is: what is the ERC20 standard? 

The ERC20 standard is one of many scripting standards ensuring that things run properly on the Ethereum blockchain. Two other popular standards, both related to NFTs, are ERC-721 and ERC-1155. Moreover, ERC20 dictates a set of particular rules, actions, and steps to implement fungible tokens on Ethereum. As such, it makes sense to call fungible tokens created on Ethereum “ERC20 tokens”. Furthermore, since tokens are created (minted) with the use of smart contracts, ERC20 smart contracts implement the ERC20 standard. Simply put, ERC20 is a set of required (and a few optional) guidelines and functions. It is these guidelines and functions that every ERC20 contract on the Ethereum chain must follow. 

Here are the rules that ERC20 contracts need to follow:

  • The contract address (essential).
  • The total supply of tokens (essential).
  • The token name (optional).
  • The token symbol (the ticker [optional]).
  • The number of decimals for the token (optional).

Here are the most common functionalities that the ERC20 contracts provide:

  • Transfer tokens between different accounts.
  • Get the current token balance of a particular account.
  • Get the total supply of a token available on the network.
  • Approve whether a third-party account can spend several tokens from a particular account or not.

Smart Contracts Explained

Not sure what smart contracts are? Don’t worry; we got you covered. You most likely know how the majority of regular contracts work, right? Usually, two parties agree upon certain conditions and actions, which must be respected by both sides for contracts to be valid. However, there is no immediate safety with regular contracts without involving several middlemen. However, when we talk about smart contracts, everything is automated. Therefore, no middlemen are required. As such, this is where smart contracts earn the “smart” title. 

Moreover, the simplest way to view smart contracts is to think of them as computer programs running on the blockchain. These programs ensure that predetermined actions execute once predetermined conditions have been met. Furthermore, those actions also follow clearly defined rules or guidelines. As you can imagine, there are countless use cases for Solidity smart contracts where this marvelous creation can be applied to ensure fairness by default. You can use an ERC20 contract to create ERC20 tokens are just one of the particular use cases of smart contracts on Ethereum. You can learn more about smart contracts and how to create smart contracts from our past articles. 

In addition, let us tell you that contrary to a general belief among blockchain developers, creating and working with smart contracts is not that difficult. That is if the right tools are used, of course. For starters, it makes all the difference if you start with verified open-source smart contract templates available at OpenZeppelin. Moreover, you can deploy smart contracts with ease using Remix. However, the real magic (for dApp development) lies in using Moralis to sync and index smart contract events. This feature makes Moralis a The Graph alternative for smart contract indexing.

Create ERC20 Tokens

If you’ve covered the above sections, you should now have a pretty clear understanding of what ERC20 smart contracts are. As such, you are ready to learn how to create ERC-20 tokens. Fortunately, this is a lot simpler than most people think. As a matter of fact, you can do this in about ten minutes with the help of Moralis. We will cover the main steps of creating an ERC-20 token below. However, for more detailed guidance, use the video below. Though, let us first guide you through the initial setup. 

Initial Setup

Before creating ERC20 tokens, you need to complete certain setup steps. These include an initial Moralis setup, acquiring Moralis Speedy Nodes, setting up MetaMask, and acquiring ETH (either play or real ETH).

Initial Moralis Setup

In order to use Moralis for your blockchain development endeavors, including to create ERC20 tokens, follow these substeps:

  1. Create Your Free Moralis Account In case you haven’t created your free Moralis account yet, do so now. On the next page, enter your email address, create your password, and click on the confirmation link (sent to your email inbox). However, if you already have a Moralis account, just log in.

Note: For the purpose of creating ERC20 tokens, you do not need to complete the substeps 2 – 4 below. However, they will come in handy when you decide to use Moralis for dApp development.

  1. Create a Moralis Server – Once logged in to your Moralis admin area, navigate to the “Servers” tab. There, click on the “+ Create a new Server” button in the top-right corner. Then, select the network type that best suits your needs (see the image below). When developing or working on example projects, it makes sense to select the “Testnet Server” option. However, to deploy functional dApps, you’ll want to select “Mainnet Server”. 

Next, enter your server’s name (this can be anything you want), select your region, network type, chain(s), and spin up your server by clicking on the “Add Instance” button:

  1. Access Server Details – In order to access the full backend functionality of Moralis, you’ll need to obtain your server’s details. These details are available via the “View Details” button: 

All the relevant details will be displayed in a new window, and you can simply copy them (one by one) by clicking on the copy icons:

  1. Initialize Moralis – By using the above details, populate your coding files (“.html”, “.js.”, “.jsx”, or “.env” if using the ultimate Ethereum dApp boilerplate):

Acquiring Moralis Speedy Nodes

When creating ERC20 tokens, you need a fully functioning node. Unless you want to face the limitations of RPC nodes by running one yourself, Moralis offers a great shortcut. Moralis Speedy Nodes are at your disposal after creating your account. As such, you can utilize this premier choice among Infura alternatives.

Inside your Moralis admin area, select the “Speedy Nodes” tab in the left-hand side menu bar:

Since you are creating ERC20 tokens, you need to select the Ethereum network by clicking on the “Endpoints” button under “ETH Network”. This will give you access to nodes on the mainnet and all of the Ethereum testnets:

The URLs you see in the image above for each network are nodes. By clicking on the “copy” icon next to the network that you decide to use, you copy the relevant address. Though, you’ll be using this with Brownie when you’re setting up your Moralis Speedy Node. 

MetaMask Setup

In case you don’t have a MetaMask account yet, make sure to set it up before moving forward. If you need help, use the details provided in our MetaMask for developers guide. Moreover, if you are not familiar with this excellent tool, we recommend learning more about building dApps with MetaMask and how to authenticate with MetaMask.

Acquiring ETH

When working on Ethereum, especially when you want to mint tokens, you need the networks’ native tokens (ETH). The latter is required to pay gas fees to complete the minting transaction. It is also good to have enough ETH to perform several testing transactions. If you are working with any of the Ethereum testnets, you get to obtain those for free from ETH “faucets”. However, if you want to deploy ERC20 tokens on the Ethereum mainnet, you’ll need real ETH. To obtain the latter, you’ll have to purchase some on any reputable centralized exchanges (CEXs) or via any other fiat gateway

The Steps to Create ERC20 Tokens

With the initial setup covered, it is time to hand you over to one of Moralis’ experts. He will guide you through the steps required to create ERC20 tokens by putting an ERC20 contract to use. These are the steps he will guide you through:

  1. Set up a Moralis Speedy Node.
  2. Add a pragma line along with importing the proper OpenZeppelin package.
  3. Create the Ethereum token contract.
  4. Test the contract.

Furthermore, towards the end of the video, you will also learn how to add ERC20 tokens to your MetaMask. 

ERC20 Transfer

Quality cryptocurrencies with real use cases behind them are fantastic, especially considering how easy it is to transfer them. Moreover, if you’ve created your own ERC20 tokens following the video above, you may want to transfer them to other accounts. If that’s the case, we got you covered. In our ERC20 transfer guide, you’ll learn that there are various ways to transfer these types of tokens. For one, you may always use CEXs; however, if you want to use a decentralized way, MetaMask is your best choice. 

Moreover, by following the link above, you’ll also learn how easy it is to integrate all various token transfer functionalities to your dApps when using Moralis. For example, if you were to send 0.5 tokens with 18 decimals, you’ll only need to copy these few lines of code and add the details for the token in question:

const options = {type: "erc20", 
                 amount: Moralis.Units.Token("0.5", "18"), 
                 receiver: "0x..",
                 contractAddress: "0x.."}
let result = await Moralis.transfer(options)

What is an ERC20 Contract? – Full Guide – Summary

At this point, you should have no problem answering “what are ERC20 contracts?” in a heartbeat. You know that an ERC20 contract is a smart contract following the details of the ERC20 protocol. Furthermore, you know that they are used to mint tokens on Ethereum and ensure that these tokens are transferred properly. As such, it now makes total sense to you that tokens on Ethereum are known as ERC20 tokens. In addition, you’ve also learned how to create your own ERC20 tokens. Nonetheless, you’ve discovered that Moralis can be used to integrate the ERC20 transfer functionality into your dApps quickly and easily.

If you’d like to expand your blockchain development horizons using free resources, we recommend visiting the Moralis YouTube channel and the Moralis blog. Both of these outlets produce high-value content on a regular basis. Some of our latest articles show you how to integrate mint function to JS interface, how to index the blockchain, how to develop an NFT rarity ranking dApp, how to connect to Avalanche nodes, how to connect to Arbitrum nodes, how to build an NFT trading interface, how to build Ethereum dApps in Angular, how do flash loans work, and much more. 

However, in case you are interested in taking a more professional approach, the one that will enable you to go full-time crypto sooner than later, then make sure to enroll in Moralis Academy. Not only will you gain access to high-quality courses, but it will also provide you with a detailed path to success. On top of that, it will give you access to mentors and an advancing crypto community.  

January 5, 2022
Moralis Blog
Moralis Blog
Become a Moralis Mage
Get the latest information about Moralis Web3 in your email
Search
Generic filters
Get Loved BY
the Web3 community

Related Articles

Join, compete & win! Current prize pool of $500,000
Become a Web3 Expert
Subscribe to our newsletter and get our E-book Web3 Speed run for FREE