Understanding The ERC-20 Token Standard
Ethereum is a pioneering blockchain network which has undergone significant transformations since its inception in 2015. Before the introduction of various regulations, the Ethereum ecosystem operated in a "wild west" mode, where token development was largely unregulated. This lack of standardization led to several issues among which interoperability among different tokens and platforms was prevalent.
To address these challenges, the ERC-20 standard, a set of rules providing a set of guidelines for creating fungible tokens on the Ethereum network was born. According to the Ethereum Improvement Proposal (EIP 20), the standard is a solution to the problems early Ethereum-based token creators faced by ensuring consistency and ease of integration across different applications and wallets.
Key Components of ERC-20
There are several methods defined in the ERC-20 token standard and it is expected that every token created on the Ethereum network is compliant with this. These functions serve as the foundation for basic token operations and they each play a distinct role. In the following section, I will attempt to break down the various methods/components.
1. Name
This field specifies the name of the token.
string public constant name;
2. Total Supply
This method returns the total number of tokens in existence.
uint256 public totalSupply;
3. Symbol
This is an abbreviation or shorter representation of the token. It is usually 3-4 characters long. An example is the stablecoin USDT, its moniker is USDT.
string public constant symbol;
4. Decimal
The decimal is the representation of the smallest number of units a given token can be divided into. Still looking at USDT as an example, USDT has 1 * 10^6 decimals.
uint8 public constant decimals;
5. BalanceOf
The balance of function allows a user to check the number of tokens they have. This function takes the address of the owner whose balance is to be checked.
function balanceOf(address owner) public view returns (uint256 balance);
6.Mint
Creates new tokens and assigns them to a specified address.
function mint(address recipient, uint256 amount) public returns (bool success);
7. Transfer
Transfer is an important operation where a user gets to perform fund transfer of token transfer. To use this method, users must specify inputs of recipient address and value to be sent to send value from their account to a recipient account.
function transfer(address _to, uint256 _value) public payable returns (bool success);
8. TransferFrom
This method allows users to perform a direct transfer of tokens from one address to another. The transferFrom
is used by third parties like decentralised exchanges to spend tokens on behalf of the token owner.
function transferFrom(address _from, address _to, uint256 _value) public payable returns (bool success);
9. Approve
In situations where an application needs to handle token transfers without needing direct control from the user, the approve
method permits another address to spend a specified number of tokens on behalf of the owner.
function approve(address _spender, uint256 _value) public returns (bool success);
10. Allowance
The allowance
method allows the amount of tokens an approved spender is allowed to spend. This Returns the remaining number of tokens that a spender is allowed to spend on behalf of the owner. This function provides security by enabling users to see how much of their token balance has been delegated.
function allowance(address _owner, address _spender) public view returns (uint256 remaining);
Events
Events are logging that are emitted when a function is triggered. It helps to log the different details of the transaction. In the ERC-20 standard definition, it requires that two events must be emitted during specific operations. Each of these functions plays a
Approval Event
The `approval` event is triggered whenever the approve function is called successfully in a transaction.
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
Transfer Event
Triggered whenever tokens are transferred, including zero-value transfers.
event Transfer(address indexed _from, address indexed _to, uint256 _value);
Conclusion
To wrap this up, though other token standards exist on Ethereum, ERC-20 is one of the most widely used and recognized standards and of course, has its distinct use case. Different organisations have used this token standard in their various projects and have modified it based on certain conditions and requirements.
Subscribe to my newsletter
Read articles from Jeremiah Samuel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by