DEV Community

Cover image for ERC20 Tokens - Explained | How Tokens are Created
EbenKouao
EbenKouao

Posted on

ERC20 Tokens - Explained | How Tokens are Created

ERC20 Tokens - the technology standard behind your favorite projects. From decentralized stablecoins such as DAI to crypto the meme coins of SHIBA. With all that's going on in within this space, ERC20 Tokens can be a whole much more than dog coin projects. Let's dive in.

What is a Token?

A token can represent virtually anything on the Blockchain that we can earn or trade with other people. Whether being XP in an online game, No. of points to a user’s profile, lottery tickets, and of course...cryptocurrencies.

erc20 standard exchanges
ERC20 Tokens - developers can utilize tokens in their applications.

However, instead of every developer building their own token implementation. (Which would be chaotic)

There needs to be some standardization, making it easier for others such as exchanges to list these tokens by building functions into the smart contract to transfer, withdraw and swap these tokens. This is where the ERC20 standard comes in.

The ERC20 standard presents a token standard that helps keep track of Fungible tokens. Meaning, each token has the exact same properties (both in type and value) when compared to another token.

Full Article: Web3, DApps, ERC20 Tokens & NFT Explained

fungible tokens
ERC20 Fungible Tokens

I.e, an ERC20 Token named ABC: One ABC Token is always equal to all the other ABC tokens. As a result, this makes ERC20 Tokens ideal for mediums of exchange - currency, staking, and voting rights.

fungible-real world coin
Real-World example of Fungible Tokens, £1 Coin

In order for a Smart Contract to be called an ERC20 Token Smart Contract, the Smart Contract would need to comply with the ERC20 token standard.(Ethereum Request for Comments 20).

web3, dapps, erc20 and nft's explained - solidity remix functions
Minting ERC20 Token Functions

Examples of the methods and events that would need to be implemented:

  • Transfer() – Transfer tokens from one account to another account /wallet address.
  • balanceOf() – Get the current token balance of the account
  • totalSupply() – Total supply available on the blockchain network (e.g. mainnet).
  • approve() – Approve whether a token amount can be spent or transferred by a third-party account. E.g. use for AirDrops etc.

web3, dapps, erc20 and nft's explained - erc20 solidity token
Smart Contract Code to Mint an ERC20 (no really, that's all!)

Constructing an ERC20 Token Contract has been made simpler with OpenZepplin; which is a library that provides reusable templates for writing a smart contract that complies with the ERC20 standard.
Using OpenZepplin, we can inherit the methods where we can change the name, symbol, and decimals. These tokens are sent to an address specified during the minting process. Being the, msg.sender argument.

By default: ERC20 uses 18 decimals. Where 1 Eth, is equal to 10^18. Or (1 Ether = 1,000,000,000,000,000,000 wei).

You can have a look at an example of an ERC20 Smart Contract in Remix. In fact, OpenZepplin provides a Smart Contract Wizard for creating your own token.

jpow-money-printer
License to Mint Tokens

As interesting as it is, this can theoretically make anyone their own federal reserve of their own currency. This may explain the 500,000+ Tokens deployed on the Ethereum main net. It’s important to note, some are only designed to part you from your cash. (Given that, anyone could literally recreate your smart contract, name, ID, and symbol). That's why, It’s important to verify the contract address, and whether it’s legitimate.

Additionally, further examples of using tokens as reward points include gaming, loyalty points in online services, or even a gift card. (In the form of cryptocurrencies).

This can even expand to social media platforms. JoinSpace.xyz is a decentralized social media platform I developed, which allows users to earn tokens based on their content quality.

Image description

Top comments (0)