Logo

dev-resources.site

for different kinds of informations.

What, exactly, is a "Token"? - Understanding the ERC20 Standard

Published at
6/18/2023
Categories
ethereum
smartcontracts
tokens
erc
Author
byteatatime
Author
11 person written this
byteatatime
open
What, exactly, is a "Token"? - Understanding the ERC20 Standard

This post was originally published on my blog!


Hello, and welcome back! Today, we’re going to dive into the intriguing world of tokens and shed light on what they how they are represented within the Ethereum ecosystem.

Tokens have become a fundamental building block in decentralized applications, enabling the creation and representation of various digital assets. In particular, we’ll focus on the ERC20 standard, which has revolutionized token development and interoperability on the Ethereum blockchain.

The Concept of Tokens

In the realm of blockchain and cryptocurrencies, a token represents a digital asset or utility that resides on a specific blockchain. Tokens can embody various forms, such as digital currencies, digital representations of physical assets, loyalty points, and more. They are often used to facilitate transactions, govern decentralized applications, or incentivize participants within a network.

However, when Ethereum first launched, it did not natively support the creation of tokens. Instead, developers had to create their own token contracts, which were often incompatible with other applications and services. This created a lot of friction within the Ethereum ecosystem, as developers had to create custom solutions for each token.

This article is about the ERC-20 standard, which covers normal fungible tokens (unlike the ERC-721 standard, which covers NFTs).

Introducing the ERC20 Standard

The ERC20 standard, or Ethereum Request for Comment 20, is a technical specification that defines a set of rules and interfaces for creating and managing tokens on the Ethereum blockchain. It solves the need of having a standardized way for developers to create tokens, especially those that are compatible and interoperable with other Ethereum applications and services.

How Does the ERC20 Standard Work?

To understand how the ERC20 standard works, let’s take a look at the ERC20 interface:

interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
Enter fullscreen mode Exit fullscreen mode

Let’s go over each of the events and functions one by one:

Events

Transfer(address indexed from, address indexed to, uint256 value)

The Transfer event is emitted whenever tokens are transferred from one address to another. It’s mostly self-explanatory:

  • from: The address from which the tokens are transferred.
  • to: The address to which the tokens are transferred.
  • value: The amount of tokens transferred.

Approval(address indexed owner, address indexed spender, uint256 value)

The Approval event is emitted whenever an address approves another address to spend tokens on its behalf. Again, it’s self-explanatory:

  • owner: The address that approves spender to spend tokens on its behalf.
  • spender: The address that is approved to spend tokens on behalf of the owner.
  • value: The amount of tokens spender can spend.

Readonly Functions

totalSupply()

The totalSupply() function returns the total number of tokens in existence. Depending on the token, this number may be fixed or variable. For example, if the token is mintable, then the total supply may increase over time.

balanceOf(address account)

The balanceOf(address account) function returns the number of tokens owned by a specific address. Duh.

allowance(address owner, address spender)

The allowance(address owner, address spender) function returns the number of tokens that spender is allowed to spend on behalf of owner. This can be changed through the approve and transferFrom functions.

State-Changing Functions

transfer(address to, uint256 amount)

The transfer(address to, uint256 amount) function transfers amount tokens from the caller’s address to to. It returns true if the transfer was successful, and false otherwise. It’s comparable to the send function in Solidity.

approve(address spender, uint256 amount)

The approve(address spender, uint256 amount) function approves spender to spend amount tokens on behalf of the caller. It returns true if the approval was successful, and false otherwise.

transferFrom(address from, address to, uint256 amount)

The transferFrom(address from, address to, uint256 amount) function transfers amount tokens from from to to on behalf of the caller. It returns true if the transfer was successful, and false otherwise. It also decreases the allowance of spender by amount.

Interoperability and Advantages of ERC20 Tokens

The ERC20 standard has revolutionized token development and interoperability within the Ethereum ecosystem. Here are some of the key advantages of ERC20 tokens:

  • Compatibility : ERC20 tokens are compatible with a wide range of Ethereum wallets, decentralized exchanges, and other smart contracts. This compatibility enables seamless integration and broader adoption of tokens within the Ethereum ecosystem.

  • Interchangeability : ERC20 tokens adhere to a standard interface, making them interchangeable. This means that tokens developed by different projects can be used interchangeably within the Ethereum network, fostering liquidity and usability.

  • Ecosystem Integration : The ERC20 standard has paved the way for the development of various Ethereum-based services and decentralized applications (dApps). It has become the foundation for token crowdfunding, decentralized finance (DeFi) protocols, and other innovative use cases.

  • Token Standards : The ERC20 standard has inspired the creation of other token standards, such as ERC721 (Non-Fungible Tokens) and ERC1155 (Multi-Token Standard). These standards cater to specific token use cases and expand the possibilities for tokenization on the Ethereum blockchain.

Conclusion

Tokens are the digital representation of assets and utilities within the Ethereum ecosystem, enabling a wide range of applications and use cases. The ERC20 standard has played a pivotal role in token development, providing a standardized set of rules and interfaces for creating and managing tokens on the Ethereum blockchain.

With its interoperability, compatibility, and ecosystem integration, the ERC20 standard has empowered the token economy and paved the way for countless decentralized innovations. So, the next time you encounter a token on the Ethereum blockchain, remember the underlying power and significance of the ERC20 standard that makes it all possible.

smartcontracts Article's
30 articles in total
Favicon
Mainnet Forking in Foundry
Favicon
How to deploy smart contracts using Foundry
Favicon
How to write and compile smart contracts in Foundry
Favicon
Building Decentralized Applications with Smart Contracts
Favicon
Building Secure Smart Contracts for DeFi Applications
Favicon
Debugging Smart Contracts on the Ethereum Network
Favicon
Building Secure Smart Contracts for DeFi
Favicon
Blockchain Security and Development
Favicon
The Impact of Smart Contracts on Construction Project Delivery
Favicon
The Impact of Smart Contracts on Streamlining Construction Payments
Favicon
The Future of Construction Contracts Smart Contracts and Blockchain
Favicon
Vyper beginner's tutorial: Variables.
Favicon
Mastering functions in Vyper(part2)
Favicon
Simplifying Solidity with Assembly: A Beginner's Guide -(Part 1)
Favicon
Compiling and Deploying Smart Contract with AWS Lambda
Favicon
How to Become a Blockchain Developer in 2024 Step-By-Step | Top Skills
Favicon
Building Together: A Personal Invitation to Create with Crowdfunding DApps
Favicon
Mastering ERC-20 Token Allowances and Transfers in Ethereum Smart Contracts
Favicon
Decoding Vyper: The Future of Smart Contracts?
Favicon
Solidity: Limitations and Expansions Explored
Favicon
Making Smart Contracts Smarter with Functions
Favicon
Decentralization: Regranting Control & Power Distribution of The Internet
Favicon
Tezos Blockchain: A Unique Approach to Decentralized Smart Contracts
Favicon
Ethereum Name Service (ENS) - What is it?
Favicon
What, exactly, is a "Token"? - Understanding the ERC20 Standard
Favicon
Best way to reduce gas fees in your smart contract 🚀
Favicon
Smart Contract Security
Favicon
Blockchain for Mobile App Security
Favicon
Deploy Smart Contract On Any EVM Chain using thirdweb
Favicon
Account Abstraction in Ethereum Blockchain

Featured ones: