ERC-20 — The Fungible Technical Standard

Aayush Grover
The Innostation Publication
9 min readFeb 12, 2022

--

I remember sitting on the couch with my dad while he was watching the news. There was some kid who became a multi-millionaire by investing in Ethereum and it caught my attention. At this point, Ethereum has turned from a cryptocurrency to a buzzword. I knew that Ethereum was this crazy new crypto that was making everybody rich, but what really IS ETH?

Ethereum — Not Actually a Cryptocurrency? 🤯

Ethereum itself isn't actually a cryptocurrency. It’s a decentralized, distributed blockchain platform.

  • Blockchain: Shared, immutable ledger of transactions using a chain of blocks that contain information
  • Decentralized Network: A system that doesn’t have a centralized authority
  • Distributed: Every node on the blockchain has a copy of the entire blockchain

Note: If you want to learn more about what these words mean, check out my article on cryptocurrencies and the blockchain.

On the Ethereum network, the native cryptocurrency of the platform is Ether (ETH). Ether is second in terms of market cap, second to Bitcoin.

  • Market Capitalization: Total value of all of the coins in circulation

ETH is the currency that powers Ethereum applications and smart contracts.

What’s a Smart Contract? 🤔

A smart contract is a contract…. but smart — pretty self-explanatory. Think of it as the digital version of a contract. This contract is actually just a file of code stored on the blockchain.

On the Ethereum network, smart contracts are coded in a language called Solidity, a language developed specifically for this network. Stay tuned — you’re actually going to be learning a little bit of Solidity today.

To elaborate on what a smart contract looks like, think of it as a bunch of functions and rules. For example, there could be a function to transfer tokens between two accounts, or burn them (completely get rid of it, used to “decrease” supply and increase value).

Smart contracts can be referred to as transaction protocols. Any time a transaction is made within a Blockchain network, the smart contract of the network is referred to. They enforce these rules that are regulated by code, getting rid of the need for a third party.

Time for an Analogy! Suppose my parents are to give me $10 but ONLY after I’m able to mow the lawn. Traditionally speaking, I have to trust that my parents will actually end up paying me (without taking months and months and pretending that they don’t know what I’m talking about). In the case of a smart contract, my parents would simply send the $10 to the smart contract, which would only send it to me once I’ve mowed the lawn.

So what? Why should I care? 😔

When you make a large purchase such as the purchase of a car or a home, we’re putting a lot of trust and faith into a centralized party. We’re giving our money in the tens of thousands to a centralized party in exchange for the house, car, or anything else.

Smart contracts completely remove the need for this centralized party and allow for transactions to be completely peer-to-peer. Ethereum allows for these trust-based transactions to be completely trustless!

Why should I trust a smart contract?

Smart contracts have two primary aspects to them which make them much more worthy of your trust than any third party — great for people with trust issues 😭 Smart contracts are:

  • Immutable: the smart contract can’t be changed once it’s created no matter what
  • Distributed: every user has access to the smart contract, meaning that every other user can spot when something fishy might be going on and deem it invalid

Due to these properties, any given person can’t force a smart contract to do something against its initial code, providing it with a high level of safety. This ensures that tampering with these smart contracts becomes ALMOST impossible.

Ethereum was designed for smart contracts... it was designed to support smart contracts that run on the native asset of its blockchain, ether.

Sooo what’s a token then? 🧐

A token is essentially a smart contract. It can represent any digital asset that can use any given function. The one that you may initially think of is money.

Think of it this way: If I want to send $10 back to my parents, I’m essentially running a function on a smart contract that allows this money to be directly sent back to my parents.

That being said, tokens can represent MUCH more than just money. They can store any sort of digital value — data, collectibles, virtual real estate, and financial instruments. You might be able to draw similarities between these, and Non-Fungible Tokens (NFTs) and that’s because NFTs are a type of token. However, the primary difference is the ERC-20 tokens are Fungible as opposed to Non-Fungible. This means that each ERC-20 token has the exact same value for every single token. NFTs utilize the ERC-721 standard, allowing them to be non-fungible, meaning that each token can have a different value depending on its contents, sparsity, etc. However, that’s another article for another day.

The way these tokens function is entirely based on the creators’ intended purpose and the smart contract that they build surrounding it.

Note: tokens and coins are two entirely different things — a token can be used to store any digital asset, as long as it remains within the confines of its smart contract while a coin is native to the blockchain network and is used to trade currencies, store value, etc.

Then what’s an ERC-20 token? 🤷‍♂️

The ERC-20 standard is essentially a scripting standard (you’ll see what this means soon enough). You might be asking, what is a standard?

Imagine if every single time you bought a new item that needed to be powered, you needed to create a new outlet because every item has a unique, different shape to it. This means that plugging in a lamp and a computer charger would require two ENTIRELY different outlets, an incredibly painful and inefficient process.

If we want our tokens and currencies to be able to function together, interact with one another, etc., we need to have a certain standard that standardizes all of this. This would mean that the overall blueprint for a token and smart contract remains the same. This also makes it much more convenient for developers who don’t need to work day and night trying to understand how hundreds of different smart contracts work! 😬

ERC-20 tokens also share standardized functions. For example, sending all tokens that are built with the ERC-20 standard would be done in the same manner and would function exactly the same from a coding point of view.

ERC-20 tokens don’t have INNATE VALUE

When you create an ERC-20 token, it isn’t given value simply by being an ERC-20 token. Value comes from the supply and demand of the token, as well as its overall market. If a token has high demand and low supply, it may have a lot of value since it’s wanted, and rare. If a token has low demand and high supply, it may have no value since it’s not wanted, and common.

How does the ERC-20 standard work?

For a token to fit the ERC-20 standard, it has to abide by certain rules. These “rules” are really just mandatory functions written within the smart contract.

Note: I’m about to mention wallet addresses shortly — wallet addresses refer to the public key of a wallet. This essentially means that if I wanted to call upon a specific Ethereum wallet, I would use its wallet address. They tend to look something like: 0x71C7656EC7ab88b098defB751B7401B5f6d8976F

There are 6 mandatory functions within this technical standard. Since these functions are constant between ALL ERC-20 smart contracts, they can be called upon in ALL ERC-20 tokens. These functions are:

  • totalSupply: defines the total supply of tokens — creates a barrier in the smart contract for when tokens should stop being produced [input: none — output: total supply]
function totalSupply() external view returns (uint256)
  • balanceOf: returns the number of tokens, aka the balance, of a given wallet address [input: address — output: address balance]
function balanceOf(address _owner) external view returns (uint256 balance)
  • allowance: checks if one user has enough tokens to send to another user — can be used to allow an account to send tokens on your behalf based on allowance set by the approve function [input: owner, spender — output: allowance from owner to that account]
function allowance(address owner, address spender) external view returns (uint256);
  • transfer: takes tokens from the total supply of tokens and transfers it to a specific wallet address [input: address, amount — output: success boolean]
function transfer(address _to, uint256 _value) external returns (bool success)
  • transferFrom: same as the transfer function, however tokens are transferred between parties instead [input: from, to, amount — output: success boolean]
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
  • approve: checks to see if a certain amount of tokens can be allocated to a given user considering supply, creates an allowance [input: spender, amount — output: success boolean]
function approve(address _spender, uint256 _value) public returns (bool success)

These functions can be split into 2 groups: getter functions, and transfer functions.

  • Getter functions don’t change the state of the blockchain and are ‘read’ functions. These functions' output has outputs that can be interpreted and have much lower gas fees than their transfer counterparts. These include: totalSupply, balanceOf, and allowance.
  • Transfer functions change the state of the blockchain and are ‘write’ functions. These functions don’t have outputs meant to be interpreted and have much higher gas fees than their getter counterparts. These include: transfer, transferFrom, and approve.

There are 3 more functions that aren’t mandatory but can be useful to have. These include:

  • name: defines the name of the token
function name() public view returns (string)
  • symbol: defines the symbol or ‘ticker’ of the token
function symbol() public view returns (string)
  • decimals: defines how man decimals token is divisible by
function decimals() public view returns (uint8)

Mint 🌿 and Burn 🔥 Functions

The mint and burn functions are two important functions that any token can have, but aren’t defined by the ERC-20 standard. They fulfill to primary purposes:

  • Allow the admin to increase the supply
  • Allows anyone to decrease the supply

The mint function essentially takes an address, and an amount as parameters (inputs) and creates tokens to increase the supply as long as the person USING this function, denoted by msg.sender, is the admin. An increase in token supply decreases the value of the token, which could potentially be useful.

The burn function essentially takes tokens from the person using this function and transfers them to the following address: 0x00….000dEaD. This is an address that has no owner, and so those coins can no longer be accessed and are removed from the total number of usable coins.

Events

Events are essentially notifications to certain users when certain functions are activated. The notifications are sent when these events are emitted.

ERC-20 has two events worth noting: approval, and transfer.

  • Approval: an event emitted everytime an owner sets an allowance for a sender through the “approve” function
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  • Transfer: an event emitted when allowance is sent by a spender using the tokens of the owner

It took a while but we finally understand ERC-20! Now what? 😅

Now that we finally understand what the ERC-20 standard is, how it works, and how we can create tokens using the ERC-20 technical standard in an intuitive sense, now what?

Well, learning something and applying your knowledge are two very different things. Now, let’s actually utilize this knowledge to create an ERC-20 token with Solidity!

If you liked this article, please check out my other articles here, or check out my article on cryptocurrencies here.

Feel free to check out my other socials: LinkedIn, Twitter

Consider subscribing to my newsletter here! I talk a lot about my progress, experiences, and my struggles. My January issue just came out where I discuss my relationship with confidence and what that means to me on a fundamental level.

--

--

Aayush Grover
The Innostation Publication

Leveraging Artificial Intelligence and Blockchain technologies to propel societal transformation this decade.