A gentle introduction to Ethereum Tokens

Nicolás Bello Camilletti
SOUTHWORKS
Published in
7 min readMay 17, 2021

Ethereum, a platform used to run decentralized applications (also known as dApps) has been around since 2015 and revolutionized the world by presenting the first programmable blockchain. This is possible by using the blockchain to store programmable Smart Contracts and transactions.

Visualizations of the relationships between a smart contract and related concepts: blocks, smart contracts (internal data, contract address, business rules) and transactions (target contract, transaction signature, transaction fee, arguments and triggering rule).
Source: https://www.logigear.com/magazine/test-automation/the-beginners-guide-to-blockchain-and-ethereum-smart-contract-testing/

Using the advantages of the Blockchain everyone can see and audit the code behind the contracts, and the underlying technology ensures that the information on the blockchain cannot be deleted or tampered in any way.

But not just that, Ethereum also opened the door for the users to create their tokens (also called sub-currencies or derived coins) in a simple way. Fast-forward some years, there are more than 380.000 derived coins and the DeFi (Decentralized finances) ecosystem grew a lot creating many supporting applications such as Uniswap (or derived applications like PancakeSwap that runs on the BSC network), a fully decentralized exchange.

Some of the popular use cases of programmable Blockchains are:

  • ICO (Initial Coin Offerings): Offering tokens as exchange for funding
  • Enable Trustless Interactions: Implementing contracts to enforce transactions between untrusted parties (For example, auctions or escrowing)
  • Proof of Existence: Registering an unpatented asset in the Blockchain and verify their existence in case that someone tried to steal it.
  • Traceability: Using blockchain as a registry for traceable assets (For example meat or coffee beans)

Lately, a new trend in the dApps world appeared around the web: NFTs. The idea behind this is modelling a collectibles exchange where the users could trade and sell their own and play games with them. The hype around the NFTs became bigger and bigger and what started as something only consumed by technical people suddenly became in the lips of everyone and was covered by all major news portals.

We wrote this article along with Leandro Dardick based on our experience dealing with customer concerns and the work done with our teams to unveil the secrets behind Tokens and show how, by using some existing resources, anyone could create their own.

Type of Tokens

Before we go into details, let’s talk about Tokens. Ethereum Tokens are digital assets that are built on top of the Ethereum blockchain. There are different kind of Tokens used in the programmable Blockchain ecosystem and many more may appear in the future.

At high level, the tokens can be divided in two types: fungible and non-fungible. But, what does it actually mean?

Well, the word fungible can be translated as consumable. The fungible tokens are the ones that can be spent and any of them could be exchanged with an equivalent. An example of that is a 20 dollar bill. If someone lend me 20 dollars and I re-payed him with a different 20 dollar bill, it will be okay since the value is not in the bill itself but instead of what it represents.

In the other hand, non-fungible tokens are exactly the opposite, the tokens are unique and can be exchanged with a similar one. Let’s put that in an example: If someone lend me his 2021 red Toyota Camri and I returned a different one, from the same year, color and model I’d be in trouble and that’s not cool at all.

The matrix below represents the differences between the tokens:

As a general idea, for each token available there is a Smart Contract deployed in the Blockchain. For fungible tokens, the only thing that is stored in the Blockchain is the amount that each wallet has, while for non-fungible tokens the Smart Contract tracks the ownership of each one of them individually.

Once upon a time, the first NFT

NFT’s are nothing new, they are around since 2017. One of the most popular ones is CryptoKitties which represented Cats (yes, cats!). Each cat had their own traits (and that’s where the uniqueness is made explicit) which differentiate them from the others available. At the same time, the cats could be bred, and their kittens would be a mixture of the traits of their parents. That logic is what allowed the CryptoKitties owners to create first-generation cats and then let the game begin. Suddenly, the voice has spread, and the cats were being sold for up to 600 ETH (around 170.000 USD).

This was surely an innovative idea, but atypical. Soon, NFT’s reached the general audience and stopped being something used just by crypto-advocates. That boosted some interesting things:

Fungible Tokens

So, now that we know what an NFT stands for and represents, what about fungible tokens? Well, the fungible tokens are used to create currencies running over the Ethereum network.

In theory, anyone can create their own currency and start using it to pay or trade for goods. In the practice is not that easy, the value that the community give to the Tokens (in terms of money) relies on the rules of offer and demand. That’s why there are a lot of tokens, some of them worth something, but most of them are just buried and worth nothing.

But not everything in the world is money. There are other clever use cases of the fungible tokens. For example, the game producer Enjin implemented his own token as a sort of coin to be used in games and created a plugin to integrate it on Minecraft. This token was authorized by the JVCEA (Japan Virtual Currency Exchange Association) as the first approved gaming token.

ERC 721, ERC 1155, ERC 20

When reading about tokens there’s a recurrent term that keeps showing up: ERC, so, what does it stand for? ERC stands for Ethereum Request for Comments and just like any other Request for Comments (or RFC), they are application-level standards to describe particular implementations.

In the case of NFTs, the ERC 721 was introduced in September 2017 and just two months after CryptoKitties was launched.

There are a lot of ERC’s in Ethereum describing different implementations, but we will focus on three of them that are related with Tokens: ERC 20, ERC 721 and ERC 1155.

The ERC 20 describes the creation and management of a fungible token, for example, a coin. The ERC defines the strategy to mint, store the balance and transfer tokens on behalf of the user.

At the same time, the ERC 721 describes the creation of NFTs. The interface is pretty similar to ERC20, but as opposite to it, the balance treats the tokens as unique, meaning that the user won’t have a many equivalent tokens, but instead will have multiple unique ones. In this case, identifying each one and being able to transfer them individually matters.

Finally, the ERC 1155 take the best part of the two worlds and join them in a single contract. ERC 1155 describes the implementation of a contract that can manage fungible and non-fungible tokens at the same time, or even several tokens of the same type.

OpenZeppelin and other base contracts

That may sound as a lot of information, but believe me, it’s important to understand the next sections. As many of other Open Source projects, Ethereum has a large community that collaborates both in the development of the platform itself as well as creating tools.

One of them, OpenZeppelin, it’s an organization that, among other things, maintains a series of tested and audited contracts, some of them implementing the ERC’s, that can be used by anyone.

Using them it’s just a matter of downloading the base contracts (There’s an NPM package for that, or for everything actually) and make your own contracts inherit from them. This will expose all the methods needed to create your own token just writing a few lines of code and without having to worry about the security or performance as the contracts are widely used and maintained by developers around the globe.

The contracts can be found in the official GitHub repository.

Apart from the base contracts, OpenZeppelin also provides some tested and ready-to-go examples of implementations for the most popular ERC’s that can be used to go from zero to hero in a few minutes. For example, ERC20PresetMinterPauser describes the implementation of a ERC20 token with some popular utilities.

OpenZeppelin Utils

Apart from the presets and base contracts, OpenZeppelin also maintains some utilities that can be used to abstract the developers for common problems.

For example:

  • AccessControl adds the methods needed to implement roles and restrict operations based on them
  • Pausable adds a mechanism to pause the execution of a smart contract in case that something that requires that happens. For example, could be used to stop the exploit of a contract if a bug is found.
  • ReentrancyGuard adds a check for a common security issue: Re-Entrancy attacks.
  • SafeMath grants math-safe operations taking care of common problems like Overflows or Underflows.

Conclusion

This article had the goal of trying to show that, even though many people believe that the Ethereum world is not accessible by everyone, it’s actually very friendly.

Once again, don’t rush to create your own token contracts with the idea of winning a ton of money that allows you to never work again. As we said, most of the success stories came from innovative solutions that gives the community something fresh and new. If we decided to create a copycat of CryptoKitties, it probably won’t be as successful as the original version and that’s because we would have nothing to show that hasn’t being seen before.

Before starting a project about Tokens take a moment to answer these questions:

  • Am I giving the community something that they haven’t seen before?
  • How will I give the tokens value?
  • Why would anyone consume my token?

If you have those answers and still think that the project makes sense, go for it!

--

--

Nicolás Bello Camilletti
SOUTHWORKS

Principal Software Developer. Microsoft MVP and Google Developer Expert (GDE).