What is ERC-20 and How Do Its Functions Define Fungible Tokens?
Introduction to ERC-20 Tokens
ERC-20 tokens are fungible digital assets that exist on the Ethereum blockchain.
A fungible token means that each token unit is identical and interchangeable with another. This is similar to fiat currencies, where each $1 has the same value as another.
ERC-20 tokens follow a specific set of standards that ensure compatibility and interoperability, allowing them to be easily traded, transferred, and exchanged across various platforms and wallets.
What is the ERC-20 Standard?
Before ERC-20, developers could create tokens with their own rules, but these tokens often had compatibility issues. They couldn’t seamlessly interact with each other, creating confusion and inefficiencies within the ecosystem.
In 2015, a proposal known as Ethereum Request for Comment was introduced to address this problem. This proposal, put forward by Fabian Vogelsteller, aimed to create a standard interface for tokens on the Ethereum network. Since it was the 20th proposal, it became known as ERC-20. This standard was later formalized as Ethereum Improvement Proposal (EIP-20).
The goal of ERC-20 was to ensure all tokens using the standard would behave consistently, making them interchangeable and easy to integrate across wallets, decentralized applications (dApps), and exchanges.
The ERC-20 standard:
Sets rules for how tokens behave, including how they are transferred and approved for spending.
Ensures consistency, so tokens can be traded easily across platforms.
Defines events and functions to allow contracts and wallets to track token movements.
Content of ERC-20
The ERC-20 standard defines a set of functions (also known as methods) and events that every token contract must implement.
The functions define how tokens behave within the Ethereum ecosystem, enabling basic operations like transferring tokens between accounts, querying balances, and approving third parties to spend tokens on behalf of a user.
While the events serve as triggers that notify off-chain applications or other contracts when certain actions, such as transfers or approvals, have taken place.
ERC-20 Core Functions
totalSupply(): Returns the total supply of tokens that exist.
// View the total supply function totalSupply() external view override returns (uint256) { return _totalSupply; }
balanceOf(account): Returns the token balance of a specific address ‘account’.
// Check balance of an account function balanceOf(address account) external view override returns (uint256) { return _balances[account]; }
transfer(to, amount): Allows users to transfer ‘amount’ token from their account to another ‘to’ address.
// Transfer tokens to another address function transfer(address to, uint256 amount) external override returns (bool) { require(_balances[msg.sender] >= amount, "Insufficient balance"); _transfer(msg.sender, to, amount); return true; }
approve(spender, amount): Allows the token owner to authorize a ‘spender’ to transfer a specific ‘amount’ on their behalf.
// Approve another address to spend tokens on your behalf function approve(address spender, uint256 amount) external override returns (bool) { _allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; }
transferFrom(from, to, amount): Transfers ‘amount’ token on behalf of a ‘from’ address to a ‘to’ address. This function allows token to be teansferred on behalf of another address, typically used after an approve() call.
// Transfer tokens on behalf of another account function transferFrom(address from, address to, uint256 amount) external override returns (bool) { require(_allowances[from][msg.sender] >= amount, "Allowance exceeded"); require(_balances[from] >= amount, "Insufficient balance"); _transfer(from, to, amount); _allowances[from][msg.sender] -= amount; return true; }
allowance(owner, spender): Returns the amount of token the ‘spender’ is allowed to use on behalf of the ‘owner’.
function allowance(address owner, address spender) external view override returns (uint256) { return _allowances[owner][spender]; }
ERC-20 Optional Functions
name(): Returns the name of the token.
symbol(): Returns the symbol of the token.
decimals(): Specifies the number of decimal places the token uses.
ERC-20 Event
Transfer(address indexed from, address indexed to, uint256 value): This event is emitted whenever tokens are transferred between addresses, whether through transfer() or transferFrom().
event Transfer(address indexed from, address indexed to, uint256 value);
Approval(address indexed owner, address indexed spender, uint256 value): This event is emitted whenever an approve() call is made. It notifies wallets and applications about the new spending allowance.
event Approval(address indexed owner, address indexed spender, uint256 value);
Benefits of the ERC-20 Standard
Interoperability: Tokens built with the ERC-20 standard can be easily traded and used across multiple platforms.
Compatibility: Wallets like MetaMask and exchanges such as Uniswap natively support ERC-20 tokens.
Efficiency: The standardization reduces development time by providing ready-made templates for token creation.
Some Popular ERC-20 Tokens
Tether USD (USDT)
USD Coin (USDC)
Shiba Inu (SHB)
BNB (BNB)
Chainlink (LINK)
Conclusion
ERC-20 tokens have become a fundamental part of the Ethereum ecosystem and decentralized finance. The standard provides a consistent framework that ensures all tokens behave predictably, allowing seamless interaction across wallets, exchanges, and dApps.
Subscribe to my newsletter
Read articles from Zainab Wahab directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by