Ask Datarella: What Are Token Contracts?

Philipp Kothe

19 November 2020

The term “Token” is frequently used in the blockchain space. Shermin Voshmgir, the director of the Research Institute for Cryptoeconomics at the Vienna University of Economics, calls them even “the killer application of Blockchains“. This blog post aims to give you a better understanding of what a Token/Token Contract is.

A Token Contract is a special type of Smart Contract, which maps blockchain addresses to balances of value units – aka tokens. These software programs hold code, which specifies a set of functions and attributes of the value units, created and managed by the contract. Just like other Smart Contracts, Token Contracts are:

1. Censorship-resistant and Tamperproof

These computer programs are hosted on Smart Contract platforms, like Ethereum. Therefore, they are maintained and executed by all nodes of the blockchain network at the same time, which makes them censorship-resistant and tamperproof. Once they are deployed to the network, they cannot be changed. 

2. Reactive 

Smart contracts cannot initiate transactions themselves, they need to be called by an External Owned Account (EOA) or another Smart Contract. Therefore, they are mostly created by EOAs, which are controlled by private keys. However, Smart Contracts can send messages to call functions of other contracts, which allows creating a Smart Contract with another Smart Contract.

3. Controlled by their Code 

Unlike EOAs, Smart Contracts do not have a private key. These programs are solely controlled by the code they hold in their persistent internal storage. Their code specifies functions, from which they can read and write to.
Read functions: allow retrieving information from the contract, for example, the balanceOf(account) function, which allows reading the balance of a certain address, or the name() function, which provides the name of a token.
Write functions:  enable, surprise, to write new information to a Smart Contract. Most common is probably the transferFrom () function, which allows subtracting from the balance of the sender’s address and add to the balance of the recipient. Another interesting write function is mint(account, amount) which allows, when called, to create new tokens and send them to a specific address, respectively, the burn(account, amount) function, to destroy tokens. Calling these functions can be restricted, so that, for example, only the address which deployed the contract can call the mint() function.

Have a look at Etherescan to check out token contracts deployed to the Ethereum Blockchain.  For example, the Smart Contract of the popular stable coin Tether (USDT). As you can see in the image below you can read from the contract, e.g. to see which addresses hold USDT or write to the contract to send tokens.

Token Contract ERC20

Types of Token Contracts

In general, you can differentiate between two major groups of token contracts by the properties of the value units they create and keep track of, fungible tokens and non-fungible tokens (NFTs). 

1. Fungible Tokens 

The value units of these smart contracts are interchangeable. Further, the Token Contract specifies the number of decimals – thus the divisibility of a token. For example, 1.000000 USDT is, divisible to six decimal places. However, one might argue that the fungibility of value units recorded on public blockchains is reduced if the transaction history is publicly available. For example, if certain tokens are sent from an address, which is known for being related to criminal activity, like a hack, they might not be accepted by exchanges anymore and therefore are not fully fungible. Therefore, only privacy tokens, like Monero (XMR), which transaction history is not traceable, can be seen as fully fungible. Another example of fungible value units created by Token Contracts, next to the monetary use case, are equal voting rights represented by tokens. 

2. Non-fungible Token Contracts

These token contracts create unique – thus clearly distinguishable value units, which are not divisible. Each token created by such a program has a unique tokenID, which makes it identifiable. Non-fungible tokens (NFT) are often used to represent real-world assets, like art or real estate. Further, popular use cases for this token type are digital collectibles, like crypto kitties, digital art or digital land. Also, an interesting use case is Blockchain Domains, like Unstoppable Domains, which use NFTs to represent “.crypto” domains on the Ethereum blockchain. 

ERC – Token Standards

With the rise of Ethereum, Token Contract Standards have been established, which enable wallet applications to hold and manage any type of tokens, complying with the standard. Therefore, the rise of standards allowed for great usability advancements. Ethereum’s standards are titled as “ERC” which stands for Ethereum Request for Comments and refers to a document that specifies rules Ethereum-based tokens must comply with.

ERC20 Standard 

The most popular token standard is probably the ERC20, which creates fungible tokens, mostly used most initial coin offerings (ICOs). It is fairly easy to create an on ERC20 contract since it only requires a couple of lines of code. By today, over 333,500 ERC20 contracts are listed on Etherescan. 

These Smart Contracts have optional functions, like a Name, Symbol or Decimal, and 6 mandatory functions:

totalSupply() Can be fixed or variable. If it is variable it can be calculated and return the total amount  
balanceOf(address _owner) Shows amount of tokens held by a provided address 
approve()  Authorizes a contract to do something e.g. withdraw tokens 
transfer(address _to, uint256 _amount) Sends tokens from the total supply to address  
transferFrom(address _from, address _to, uint256 _amount) Sends tokens between two accounts 
allowance(address _owner, address _spender) Similar like approve but checks for sufficient balance of an address   

ERC721 

The predominant standard for Non-Fungible Tokens is the ERC-721 standard. Over 7,500 contracts emitting this type of tokens are listed on Etherscan.
Popular tokens created by ERC-721 are, for example, digital football player cards of sorare, blockchain domains of unstoppable, and also the famous cryptokitties as mentioned above. 

Conclusion

Token Contracts are computer programs, which create and manage value units and are deployed to Smart Contract Platforms. These code snippets are at-will programmable and can be designed to fit any kind of use case, from digital currency to collectible. Further, they can be programmed to create self-reinforcing positive feedback loops to bootstrap Web3 platforms and are the basis of any Token Economy. Stay tuned!