Photo by Shubham Dhage on Unsplash
ERC-20: The Ethereum Token Standard
Understanding the standard behind Ethereum tokens
Table of contents
No headings in the article.
What is a token?
Within the blockchain landscape, tokens are digital assets created through smart contracts on blockchain platforms. These tokens are used for various purposes such as granting access rights for a service or product, to represent ownership of an asset. These tokens are created to enable individuals to transfer, trade or utilize these assets with dApps.
Due to the absence of a standardized approach in creating tokens, there were compatibility issues that made it difficult to exchange tokens across different platforms. This challenge resulted in the creation of ERC-20, a standard for creating tokens on the Ethereum network.
What is ERC-20?
ERC-20 is a technical standard that details all the rules and functions that a token must implement for it to be considered a complete and compatible Ethereum token.This standard ensures that all ERC-20 token can interact seamlessly with smart contracts and dApps on the Ethereum network effectively solving the challenge of compatibility among tokens.
In the standard, certain functions and events are compulsory in order for the token to considered compliant.
The token must have the following functions:
TotalSupply
// This function returns the total number of tokens that exist within a particular token contract.
function totalSupply() external view returns (uint256);
BalanceOf
// This function returns the number of tokens of a specific address on the blockchain
function balanceOf(address account) external view returns (uint256);
Transfer
// This function is the primary method for moving tokens from one address to another address
function transfer(address _to, uint256 _value) public returns (bool success)
TransferFrom
// this function allows a third party to transfer tokens on behalf of a token holder
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
Approve
// This function allows a token holder to authorize another address to spend a specified amount of token on their behalf
function approve(address _spender, uint256 _value) public returns (bool success)
Allowance
// This function is used to check the remaining amount of tokens a spender is allowed to transfer on behalf of the token holder
function allowance(address _owner, address _spender) public view returns (uint256 remaining)
ERC-20 Mandatory Events
Two event are compulsory in the implementation of ERC-20 Standard. They are Transfer and Approval
Transfer Event
The transfer event is emitted when tokens are successfully transferred from one address to another. This includes transfers carried out using both the transfer
function and the transferFrom
functions. This event serves to record all token transfers on the blockchain.
Approval Event
The approval event is emitted to record the approval of a spender to spend tokens on behalf of a token holder. The event is triggered when the ‘approve’ function is called.