The Basic Guide to Functions in Ethereum Tokens
Ethereum is a very popular crypto currency platform which allows developers to create decentralized applications – DApps. It has two basic functions. One of them is a blockchain that can record transactions. The other one is a virtual machine which can execute smart contracts which are deployed to Ethereum blockchain.
Tokens are the most widely used smart contracts on the Ethereum blockchain. These tokens represent digital assets which have some values attached to them. There are several different tokens which may be used in conjunction with Ethereum. These aren’t the same as Ether, which represents the main currency of the Ethereum blockchain.
They all follow the token standard called ERC-20. This standard defines a list of rules for developers to follow, to make everything compatible. It is a minimum set of functionalities that a token must adhere to. Most tokens add even more non-standard functionalities.
Before diving into the non-standard functions, let’s first take a look at the standard ones. There are six of them and their overview is as follows:
- totalSupply()
This function calculates and returns the total amount of the token that exists in circulation.
- balanceOf()
This function stores and returns the balance of the provided address. As the function accepts any address as a parameter, the balance of the address is always public.
- transfer()
This function allows a certain number of tokens to be transferred from the total supply of the owner of the contract to another address.
- transferFrom()
This function might seem very familiar to the transfer function, but it has some differences. It allows a smart contract to automate the token transfer process from an owner to another user. Instead of sending money manually, we can set up automatic payments and let a contract send a certain amount of tokens to another address on our behalf.
- approve()
This function gives a permission to given address to spend a certain amount of tokens.
- allowance()
This function checks the allowance that one address has for another. Before a transaction takes place, it will check the balance of the user’s account and will cancel the transaction if there are insufficient tokens.
Beyond above functions, it is worth mentioning these three optional fields which are mostly standardized by now:
- Token Name
Many popular tokens include a token name field so that popular wallets can identify them more precisely.
- Token Symbol
Most tokens don’t need a full name to be identified. They can be recognized by their three or four-letter abbreviations like BTC, ETH, TRX.
- Token Decimals
This field determines to what decimal place the amount of the token will be calculated. The most common number of decimals is 18.
Now, let’s look at some non-standard functions. There are a variety of them, but we will only tackle the most important ones. These are mostly affecting centralization and therefore makes people angry.
- mint()
Token mint is an industrial facility to manufacture coins that can be used as currency. This function is mostly used during crowdsales. If there is a case that number of tokens issued have been completely consumed, and there are still investors coming in for the crowdsale, tokens need to be minted right away.
- freeze()
Freeze function is an ability to pause and resume token transfers, if instructed by a regulatory body. Some developers don’t want their token to be transferable during some initial period like crowdsale. Others use it as a mere precaution against hacker attacks.
- burn()
Burning a token means making that token permanently unspendable. This is usually done to increase the value of the individual token by decreasing the total supply of the same token.