-
Setting a token standard like ERC-20 enables different developers, working on different projects, to write smart contracts for tokens which have the same naming and syntax conventions, even though the different tokens and smart contracts themselves have been created for a wide variety of different purposes and to achieve different outcomes. This enables interoperability between different smart contracts and applications, which in turn leads to more efficiency within the ecosystem as a whole. For example, by programming a new token according to the ERC-20 standard, this will automatically make it compatible with wallets and other applications which already interact with smart contracts for other ERC-20 tokens. Therefore, existing wallets will be able to display account balances for the new token, and it will be much easier for exchanges to list it. In addition, once a developer has learnt to write smart contracts according to a particular token standard, the same task then becomes easier and quicker to perform, leading to an increase in the developer’s productivity in that particular area.
-
Functions in the ERC-20 Token Standard Interface:
function name()
Returns the name of the token e.g. “Basic Attention Token”.
function symbol()
Returns the abbreviation used to represent the token e.g. “BAT”.
function decimals()
Returns the number of decimals the token uses.
e.g. ‘8’ means that when displaying the token amount to users, the decimal point is placed before the last 8 digits of the corresponding numerical value in Ethereum.
e.g. ‘0’ means that a token is indivisible.
function totalSupply()
Returns the total number of tokens in circulation. This is equal to the sum of all address balances for the token.
function balanceOf(address _owner)
Returns the total number of tokens held in a specified account address (_owner
).
function transfer(address _recipient, _amount)
Transfers a specified number of tokens (_amount
) from the sender’s account to another user’s account address (_recipient
).
The following two functions enable a user to pay a smart contract for performing operations:
(i) function approve(address _contract, _amount)
This first allows a specified smart contract address (_contract
) to withdraw tokens from the user’s account multiple times, up to a specified limit (_amount
) i.e. the user is effectively setting a budget, and giving the smart contract an allowance, for future operating costs.
(ii) function transferFrom(address _user, address _contract, _amount)
Whenever the user asks the smart contract to perform a certain operation, the smart contract now has the necessary permission to transfer a set number of tokens equal to the cost of that particular operation (_amount
) from the user’s account address (_user
) to the smart contract address (_contract
), provided that both the user has sufficient tokens in their account to cover the cost and the smart contract’s allowance limit will not be exceeded.
function allowance(address _owner, address _contract)
Returns the amount of tokens a specified smart contract address (_contract
) is still allowed to withdraw from another specified account address (_owner
) i.e. the funds a smart contract is still entitled to withdraw from another account.