ERC-20 Tokens
Learn about ERC-20 Standard for tokens
There is only a single native token to a chain. However, to allow to represent a wide range of assets on EVM-chains, the ERC-20 token standard was developed. "ERC" stands for Ethereum Request for Comment, and "20" is the proposal identifier.
ERC-20 tokens are fungible, meaning each token is identical and can be exchanged on a one-to-one basis. These tokens are typically created and managed through smart contracts that adhere to the ERC-20 standard, which defines a set of rules and functions that ensure interoperability between different tokens and decentralized applications (DApps).
At the base of an ERC-20 token smart contract, there is a simple mapping of addresses to numbers, which represent the amount of tokens an address holds (balance).
These addresses may belong to EOA or contract accounts. Both of these can hold and transfer ERC-20 tokens.
ERC-20 tokens can represent various assets, from digital currencies to tokenized assets, and they play a crucial role in the crypto ecosystem by enabling the creation of decentralized applications with diverse functionalities, such as token sales, decentralized finance (DeFi) protocols, and more.
Interface
To maintain compatibility with dApps designed to work with the ERC20 standard, all ERC20 tokens implement the following interface:
Click here to review the ERC20 standard in full detail.
Transfer Tokens
Transferring ERC-20 tokens between accounts involves calling the 'transfer' function, specifying the recipient’s address and the amount to transfer.
To facilitate more complex interactions, such as those involving smart contracts, the ERC-20 standard includes the approve()
and transferFrom()
functions. We will check how to implement those so smart contracts can use funds according to its code.
approve()
Since all balances are just a mapping of amount values to addresses, the owner of each address can 'approve' some other account as a _spender of their funds up to some limit determined by the approved _amount. The spender then will be able to withdraw from your account multiple times, up to the value set in amount.
allowance()
Returns the amount which _spender is still allowed to withdraw from _owner.
transferFrom()
Transfers _value amount of tokens from address _from to address _to