paint-brush
The Ultimate Guide to Crypto Tokensby@yourdevopsguy
1,275 reads
1,275 reads

The Ultimate Guide to Crypto Tokens

by Your Coding TeacherSeptember 5th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

You have probably heard lately the terms tokens, crypto tokens, and cryptocurrencies. In this article, I will cover in depth what crypto tokens are, how they are created, what they are used for and how they differ from cryptocurrencies along with the most common questions around this topic.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - The Ultimate Guide to Crypto Tokens
Your Coding Teacher HackerNoon profile picture

You have probably heard lately the terms tokens, crypto tokens, and cryptocurrencies. In this article, I will cover in depth what crypto tokens are, how they are created, what they are used for and how they differ from cryptocurrencies along with the most common questions around this topic.

Before diving into the crypto universe, let’s begin by examining one of the most common meanings of the word token, outside of the context of blockchains. The Merriam-Webster dictionary defines a token as “a piece resembling a coin issued for use (as for fare on a transportation system) by a particular group on specified terms“.

Real-Life Examples of Tokens

Not all tokens need to resemble coins, but they do all represent something: from ownership of an asset (for example, your house) to access rights (for example the right to hop on the bus – even though you do not own it), rights to vote, etc.

These are some tokens you have probably utilized in the past:

  • Cinema tickets act as tokens: they are issued by the cinema and represent your right to access the movie theater.
  • In some arcades, you need to purchase “coins” (tokens) that you can insert into the machines to turn them on or unlock them. They are not money. They have no value outside of the arcade.
  • You see tokens in board games too. If you play Monopoly and manage to buy 3 “houses” and 5 “hotels”, you don’t own them in real life. You only own the tokens that represent them in the game.
  • Casino chips
  • ID cards
  • Plane tickets
  • Etc.

What are Crypto Tokens?

Crypto tokens do not look like coins. They are not even tangible. They live in a blockchain. However, crypto tokens are very similar to regular tokens:

  • They have a certain use, for example, representing the ownership of an asset or being used as a currency.
  • They are issued by a person or group. In this case, organizations make use of smart contracts to create their crypto tokens.

In fact, a crypto token is just a smart contract. It is not a separate technology. Any smart contract platform you already know, like Ethereum, can be used to create new tokens.

These contracts are usually known as token contracts (although conceptually they are not special, they are just regular smart contracts) and they can be used to represent both digital and physical assets or access rights to someone else’s assets (we will see this later in the article).

Similar to how owning an equity share represents the ownership of a piece of a company, tokens can represent the ownership of a company, real estate, etc. Furthermore, crypto tokens make it easy to own only a percentage of the asset and to easily, cheaply and quickly trade it with someone else.

Since crypto tokens are a blockchain-based technology, they come with the following out-of-the-box advantages:

  • Crypto tokens can be issued and traded on a blockchain without the need for intermediaries or centralized authorities.
  • Everything in the blockchain is public and verifiable, which increases the transparency of the system.
  • Possibly lower transaction costs, which could bring tokenization to sectors where it has been traditionally hard to achieve like the real estate example above.

Note

Smart contracts are simply pieces of code that are executed in a blockchain. If you need a refresher on smart contracts, check out this article and watch this video where I explain how a simple smart contract works line by line.

Fungible and Non-Fungible Tokens

Before exploring fungible and non-fungible tokens (NFTs), let’s take a step back and examine what fungible and non-fungible assets are.

Fungible Assets and Fungible Tokens

In economics, an asset is considered fungible when it can be interchanged with another asset or good for the same value. These are some examples of fungible assets:

  • Currencies: any two $10 bills hold the same value. Even if they have different serial numbers, in value, they are the same. If you go to a shop to buy a bottle of water, you can use either one to pay because they both are worth the same.
  • Gold. Any two ounces of gold are considered the same everywhere.
  • Financial instruments like commodities, shares, options are fungible assets.

Fungible tokens are the blockchain representation of this idea. At the code level, writing a fungible token is straightforward. Since all tokens are interchangeable, there is no need to keep track of each individual token. You just need to create a list to keep track of all the owners and a mapping that stores how many tokens each user owns.

The following is not real code, but it serves to illustrate the idea (this is what programmers call pseudo-code):

// List of owners
owners = ["Alice's Address", "Bob's Address", "Carol's Address"]
// Mapping to represent how many tokens each user owns
balances = {"Alice's Address": 14, "Bob's Address": 7, "Carol's Address": 31}

// To transfer X tokens to user _to
function transfer(address _to, int X) public {...}

Once this functionality is in place, User A just needs to send a transaction to this contract invoking the transfer function, specifying how many tokens he wants to transfer to User B. User A’s account is debited X tokens and User B’s account receives a credit of X tokens. This change is simply reflected with an addition and a subtraction in the balances mapping you have created.

Non-Fungible Assets and Non-Fungible Tokens

On the contrary, non-fungible assets have something that makes them unique and cannot be changed for another asset for the same value.

For instance, if you lend a friend your car, he cannot return a different car, even if the make, model, color, etc are the same as yours. Your car has unique qualities that affect its value. While the car is a non-fungible asset, gas is fungible and your friend can fill the tank anywhere as long as it is the same type of gas.

While gold is a fungible asset, diamonds are not. Each diamond has different properties: color, size, grade, etc. This makes it impossible to interchange any two diamonds for the same value.

The same applies to real estate. Even if two houses are identical and in the same street, they will have qualities that will make them unique and non-interchangeable: hours in the sun, noise from the surroundings, level of traffic, views, etc.

Non-Fungible Tokens represent these ideas on a blockchain. NFTs derive value from the assets or goods they represent and as well as fungible tokens, they can be transferred to other users.

Also, NFTs are unique (non-interchangeable). To reflect this uniqueness in the code, each token will have its own ID. The smart contract for an NFT needs to keep a list of all the tokens it has minted as well as mappings to easily figure out who owns a particular token.

This is pseudo-code again, just to illustrate this idea:

// List of owners
tokens = ["TokenID 1", "TokenID 2", "TokenID 3"]
owners = ["Bob's Address", "Carol's Address", "Alice's Address"]
// Mapping to represent who owns each token
ownerOf = {"TokenID 1": "Bob's Address", "TokenID 3": "Alice's Address", "TokenID 2": "Carol's Address"}

// To transfer token with id tokenID to user _to
function transfer(address _to, int tokenID) public ...

Types of Tokens Based on Their Purpose

Because there is no central authority in the crypto world, there is no official classification of tokens. However, depending on their purpose, we can divide them into different categories.

Currency Tokens

Currency tokens or cryptocurrencies behave like American Dollars, Euros, British pounds, or any other currency you are used to. They are a payment method for your purchases and they can be exchanged for different cryptocurrencies, the same way you can exchange rupees for dollars if you need to travel to the US.

The most well-known cryptocurrency is Bitcoin. Today, you can use Bitcoin as a payment method for many products and services, both online and offline.

Asset-Backed Tokens

These tokens are backed by real-world assets: gold, real estate, diamonds, etc.

You have probably come across the term Stablecoin. The aim of Stablecoins is to reduce the volatility that most cryptocurrencies experiment still today. These crypto tokens are pegged to less volatile assets, for instance, fiat currencies.

For example, Tether (USDT) is pegged to USD. On their website, we can read: “Every Tether token is always 100% backed by our reserves, which include traditional currency and cash equivalents and […]. Every Tether token is also 1-to-1 pegged to the dollar, so 1 USD₮ Token is always valued by Tether at 1 USD.”

Reward Tokens

These tokens are used to reward users for certain behaviors. For example, the Brave browser gives BAT (Basic Attention Token) to users who accept seeing ads that run in the Brave network.

Governance Tokens

Governance tokens represent voting power on a blockchain project. For instance, holders can vote on decisions affecting the project’s roadmap, who to hire for the team who is working on the project, the governance mechanism of the project itself, etc.

A very famous governance token Maker (MKR). The holders of this token can vote on decisions that control the way the protocol on which DAI (another stablecoin) runs.

Utility Tokens

These tokens are issued with a specific purpose, usually to serve as a payment option for purchases within the application where they are developed. For example, BAT (we mentioned it already in a previous category) is a token that can be exchanged between publishers, advertisers and users of the BAT network, but it has no use outside of this context.

Utility tokens are also used as a crowdfunding mechanism, where people can buy coins during ICO (Initial Coin Offering), similar to when companies go public and can be acquired in IPOs (Initial Public Offering). We will cover ICOs in more detail in an upcoming section.

Security Tokens

Security tokens are used to invest in a company and profit from dividends, market appreciation, etc. They do not represent ownership of the asset though.

Since these tokens fall under the category of Securities, trading them is a heavily regulated activity (the particular laws depend on the location).

The value of these tokens is expected to rise or fall depending on the underlying asset, like stocks. This is, if the company performs well, the holder may make a profit just like the holder of stocks of a company that is doing well.

In contrast, utility tokens’ value is usually disconnected from the performance of the application and follows the law of supply and demand.

Equity Tokens

They represent a share of the ownership of an asset. The difference with securities is that the holders own a percentage of the asset. For example, you may own 1/10th of a house.

Creating Your Own Token

Let’s now write our own token in Ethereum using Solidity. Even if you are not comfortable with Solidity, do not skip this section. The code contains comments that will make it easy for you to understand what we are doing. It is important that you follow this part because it will show a big problem (we will explore the solution to this problem later).

Let’s start by gathering some requirements, in plain English, and then we will translate them into Solidity:

  1. Initially, the organization who issues the tokens will own all of them.
  2. We need to know how many tokens we have issued.
  3. Also, we need to keep track of who owns how many tokens.
  4. We want to allow users to transfer tokens to other users.

We can write this simple token in Solidity as follows:

pragma solidity 0.4.24;

contract BasicToken {
    // Total number of tokens we've issued (Requirement 2)
    uint256 totalSupply_;
    // To represent who owns how many tokens (Requirement 3)
    mapping(address => uint256) balances;
    
    // Initialize the system. This code only runs once, when we deploy the contract
    constructor(uint256 _initialSupply) public {
        // Set initial token supply (Requirement 2)
        totalSupply_ = _initialSupply;
        // Assign all tokens to the creator of the token (Requirement 1)
        balances[msg.sender] = _initialSupply;
    }
    // Get the total number of tokens we have issued (Requirement 2)
    function totalSupply() public view returns (uint256) {
   		return totalSupply_;
    }
    // Retrieve how many token a user owns (Requirement 3)
    function balanceOf(address _owner) public view returns (uint256) {
   		return balances[_owner];
    }
    // To transfer a certain amount of tokens to another user - represented by _to (Requirement 4)
    function transfer(address _to, uint256 _value) public returns (bool) {
        // Verify that the receiver of the tokens is a valid account
        require(_to != address(0)); 
        // Verify that the sender has enough tokens to transfer to the receiver
        require(_value <= balances[msg.sender]);
        // Update sender and receiver balances
        balances[msg.sender] = balances[msg.sender] - _value;
        balances[_to] = balances[_to] + _value;
        return true;
    }		
}

(Gist: here)

For simplicity and brevity, the code that lets the contract receive ether, checks that the buyer has sent enough ether to purchase tokens, etc. has been left out of this example. However, it doesn’t change the scenario we want to analyze.

Armed with this, we could already create our own token. Initially, we, as the organization, own all the tokens. When a user buys a token, we transfer the tokens to the user, which translates to updating the balances in the contract.

After that, because it is a decentralized system users can start trading tokens on their own. They just need to send a transaction to the smart contract, where they specify the address of the person that is going to receive the tokens and how many tokens they want to send.

Need For Extensibility

Imagine now that we want to list our token on an exchange. This way, people can sell their tokens for other currencies (like US dollars, Euros, or cryptocurrencies like Bitcoin and Ethereum). The exchange needs to know how to interact with our contract to buy tokens and then to transfer them to other users. In other words, the exchange needs to write code to interact with our token.

Other organizations may implement their own tokens differently from ours, forcing the exchange to write more code to accommodate the new tokens. If more organizations start creating their own tokens and want to list them on exchanges, every exchange will have to write some code to accommodate each new token. This approach is not extensible.

Ideally, exchanges only write one piece of code to interact with any type of token, so that they can accept new tokens without any changes to their code.

This applies not only to exchanges but to any application that wants to have the ability to interact with any type of token.

In the next section, we will see how this problem is solved.

Standards for Crypto Tokens

How do we create these sorts of standards in Solidity? Using the concept of interface. Interfaces are common to many object-oriented programming languages. You can think of an interface as a set of rules. All contracts that want to be compatible with the interface need to follow these rules. In more technical terms, interfaces define what needs to be done, this is, all the functions that need to be implemented so that other pieces of code can interact with the interface.

The concept of interface allows for the extensibility of our tokens. Developers (from exchanges, decentralized applications, etc.) can write code that expects a certain interface. Any token that implements that particular interface will be automatically accepted by their code. From the perspective of the developers, their code is extensible: they can attach more and more tokens without having to change a single line of code.

However, this does not completely solve the problem. We have just shifted it. Now, instead of having thousands of different smart contracts for thousands of different tokens, we may end up having thousands of interfaces. This is not much better.

Some of these interfaces will be good. Some will be very poor. What we need here is standardization. We need to define a common set of rules. This is common in any industry.

We can define one single, high-quality interface that developers (both the creators of the tokens and third-party applications like exchanges, decentralized applications, etc.) can learn and use. This is the standard we are looking for.

All tokens that follow those rules will be considered equivalent, from the coding perspective. In our context, this will make it possible for exchanges to accept any token that follows the standard.

Note

In Solidity, you can declare an interface like this:

pragma 0.4.24;

interface ValidToken {
    // Example function. We only specify what they look like, not what they do
    function transfer(address _to, uint amount) public;
    function aSecondFunction() public;
    function anotherFunction() public;
    ...
}

contract X is ValidToken {
    ...
}

(GIST: here)

For our token to comply with the interface, we need to explicitly say that our contract implements that interface and also write the code for each of the functions in such interface. It would look something like this:

contract BasicToken is ValidToken {
    function transfer(address _to, uint amount) public {
    	// Here we write the logic of the function        
    }
    function aSecondFunction() public{
        // Here we write the logic of the function
    }
    function anotherFunction() public{
    	// Here we write the logic of the function        
    }
    ...
}

(GIST: here)

Since the aim of the article is not implementing a standard-compliant token, I will leave the rest of the code out of this text.

Ethereum Crypto Tokens Standards

Now that we have seen the importance of standards for a smooth interaction between tokens and different applications, let’s explore some of the most common standards for fungible and non-fungible tokens in the Ethereum ecosystem.

Ethereum Standards for Fungible Tokens

We have already seen the basic idea behind fungible tokens. Like fungible assets, fungible tokens can be interchanged for other assets of the same value.

The most popular standard for fungible tokens on the Ethereum ecosystem is the ERC20 standard. At the time of this writing, you can find more than 435,000 ERC20 tokens on Etherscan. Notable examples of ERC20 tokens are Tether, Uniswap (Governance Token), BAT, or COMP.

While there are three optional functions that don’t need to be coded, all ERC20 tokens must implement six functions that allow:

  • To keep track of how many tokens have been minted.
  • To know the balance of every user, this is, how many tokens each user owns.
  • Users to transfer their own tokens to others.
  • Tokens to be approved so they can be spent by another on-chain third party.

Let’s quickly expand on these 2 last points. This standard allows User A to transfer his tokens directly to User B, which is what anyone could expect for something that behaves like a currency. If you have a $20 bill, you can give it to someone else, use it to pay for goods and services, etc.

This standard also allows User A to transfer tokens he does not directly own, but he has received approval for. User C could authorize User A to transfer a certain amount of tokens on his behalf. After this approval, User A can transfer up to that amount of tokens as if they were his own.

You can see all the technical details of this standard here.

Developers have found some “flaws” in the ERC20 Standard. For example, ERC20 tokens only accept ether. If you wanted to use ERC20 tokens to buy more tokens, the contract would not know how to handle this scenario and the tokens you sent would be lost forever. The Standards ERC223, ERC827, and ERC621 Standards (among others) aim to address this issue.

Ethereum Standards for Non-Fungible Tokens

Just as a quick reminder, non-Fungible tokens, like non-fungible assets, are unique and cannot be interchanged for another asset of the same value. An analogy to grasp the idea of non-fungible assets is owning a piece of art. Imagine you own a Picasso painting. That painting is unique. There might be 1000 fake copies, but the one you own is unique and cannot be replaced with any of the copies.

The most popular Ethereum standard for NFTs is the ERC721 Standard. This standard makes it easy to create tokens that represent collectibles, artwork, property, access rights, loans, etc.

The interface (set of functions/rules) for this standard is a bit longer than for the ERC20, but the main ideas are there:

  • Checking the balance of each user.
  • Finding the owner of a given token.
  • Transferring tokens from User A to User B.
  • User C can approve token transfers for User A and User A can transfer them as if he owned them.

ERC721 is just one standard to create non-fungible tokens. It comes with its own pros and cons. For instance, you need to create a new contract for every type of non-fungible token. This may cause an explosion in the number of contracts to accommodate all the new tokens. The ERC1155 Standard, for example, tries to solve this limitation.

Differences Between Crypto Tokens and Cryptocurrencies

Now that we have covered crypto tokens in depth, we are in a good position to understand the differences between crypto tokens and cryptocurrencies.

Words like cryptocurrency and tokens are often used interchangeably, even though they are not equivalent. Even on media outlets (which should know what they are talking about) they tend to over utilize the term cryptocurrency and use it to refer not only cryptographic-based digital currencies but to tokens which represent anything: physical goods, securities, tickets for a concert, pieces of art, etc.

All cryptocurrencies are tokens, in the sense that they represent value, but not all tokens have to be cryptocurrencies. They can be used for other purposes as we have seen all through this article. Here’s another example outside of the realm of currencies: tokens could be used to issue university diplomas on the blockchain, leveraging all the benefits of blockchain-based applications like security, transparency, non-repudiation, etc.

In addition to this, cryptocurrencies are native to a blockchain and are needed to create transactions. For example, you need Satoshis to create transactions in Bitcoin and Ether to create transactions on Ethereum. These currencies give people the incentive to mine blocks, abide by the rules of the protocol, etc. In short, they are needed to keep the blockchain running.

In contrast, tokens are built on top of existing platforms. Once you have a platform where smart contracts can run, you can build tokens that operate on top of that blockchain like BAT, DAI, Maker and all the other tokens we have covered in the article. However, they are not essential to the basic operations of the underlying blockchain (Ethereum in our previous example). If you want to purchase tokens or transfer your tokens to another user, you still need Ether to create the transactions that allow for these two operations.

Initial Coin Offering

You can imagine Initial Coin Offerings (ICOs) as the Initial Public Offerings (IPOs) of the crypto universe.

ICOs are a form of fundraising via cryptocurrencies. Usually, these events are public, this is, anyone can participate and purchase tokens. However, private ICOs, where only a limited number of investors can participate, are also possible. ICOs eliminate intermediaries from the capital-raising process and directly connect blockchain companies and investors.

The way ICOs normally work is as follow:

  • Companies define a funding goal and make public their intention to raise funds along with all information about the project that potential investors may find useful.
  • Tokens are created, a process that we have already covered extensively in this article.
  • The ICO event is promoted. Interestingly, some online platforms have banned the advertising of ICOs (we will see in a minute why).
  • The ICO starts. Tokens can be purchased in exchange for other more established cryptocurrencies, like Bitcoin or Ethereum. This step may consist in one or multiple rounds where investors can buy tokens.
  • Once the funding goal has been achieved, the project launches and the tokens are released to the buyers.

ICO Scams

Although ICOs are used for legitimate fundraising, for example for startups or charities, ICOs have also been used for fraud. Some of the “techniques” these scammers have followed are:

  • Launching ICOs in exchanges that don’t have an established reputation.
  • Bounty scams, where promoters of the ICO are not paid for their work.
  • “Pump and dump”, based on fear of missing out (FOMO): when the price of the token inflates, the scammers just sell them for a profit instead of continuing working on the project.
  • Creating a fake project: fake founders, fake team, fake social media, fake everything.
  • “Exiting” the project and running away with the money.

An infamous example of this last type of scam was the one perpetrated by Prodeum, a project that raised over 60 million dollars. They promised they would “revolutionize the fruit and vegetable industry”. In the end, they ran with the money and left their investors with this message on their website:

ICO Regulations

Different countries have taken different positions regarding Initial Coin Offerings. For example, while China and South Korea prohibit ICOs, countries like Australia, New Zealand, and the United Arab Emirates have published guidelines governing ICOs. Many countries in  Europe, as well as the United States and Canada, are working on the regulation of ICOs.

Interoperability

Can you imagine if you could not use your Gmail account to send emails to an account on Outlook? If exchanging information between email platforms built on different infrastructures was not possible, email wouldn’t be such a popular technology today. 

The same could go for mobile operating systems (android users not being able to text or call iPhone users) and an endless number of technologies we use on a daily basis. We assume we can connect applications built on different platforms seamlessly. 

However, as of the time of this writing, this is not the case for crypto tokens: tokens live within their blockchains and cannot cross to other platforms. For example, ERC20 Ethereum tokens cannot be used to operate on tokens built on a different smart contract platform, since the different blockchains usually have different standards.

Projects like Polkadot, Lisk, and Cosmos, among others, are trying to solve this issue, which could immensely increase the adoption, value, and usage of tokens since different blockchains could be connected, increasing network effects.

Conclusion

I hope after reading this article you have a clearer idea of crypto tokens, what they are, how they are created, the ideas behind fungible and non-fungible tokens, the different types of crypto tokens based on their purpose, and how they differ from cryptocurrencies.

You can read more of my content on my blog and follow me on Twitter.

If you have enjoyed this article, share this article with your friends and visit our FREE crypto course where we will teach you everything about Bitcoin, Ethereum, Smart Contracts, Dapps, Oracles, DeFi, and much more.