ERC-20 Token Standard | ethereum.org (2024)

c

Last edit: @corwintines(opens in a new tab), June 11, 2024

Introduction

What is a Token?

Tokens can represent virtually anything in Ethereum:

  • reputation points in an online platform
  • skills of a character in a game
  • financial assets like a share in a company
  • a fiat currency like USD
  • an ounce of gold
  • and more...

Such a powerful feature of Ethereum must be handled by a robust standard, right? That's exactlywhere the ERC-20 plays its role! This standard allows developers to build token applications that are interoperable with other products and services. The ERC-20 standard is also used to provide additional functionality to .

What is ERC-20?

The ERC-20 introduces a standard for Fungible Tokens, in other words, they have a property that makes each Token be exactlythe same (in type and value) as another Token. For example, an ERC-20 Token acts just like the ETH, meaning that 1 Tokenis and will always be equal to all the other Tokens.

Prerequisites

  • Accounts
  • Smart Contracts
  • Token standards

Body

The ERC-20 (Ethereum Request for Comments 20), proposed by Fabian Vogelsteller in November 2015, is a Token Standard thatimplements an API for tokens within Smart Contracts.

Example functionalities ERC-20 provides:

  • transfer tokens from one account to another
  • get the current token balance of an account
  • get the total supply of the token available on the network
  • approve whether an amount of token from an account can be spent by a third-party account

If a Smart Contract implements the following methods and events it can be called an ERC-20 Token Contract and, once deployed, itwill be responsible to keep track of the created tokens on Ethereum.

From EIP-20(opens in a new tab):

Methods

1

function name() public view returns (string)

2function symbol() public view returns (string)

3function decimals() public view returns (uint8)

4function totalSupply() public view returns (uint256)

5function balanceOf(address _owner) public view returns (uint256 balance)

6function transfer(address _to, uint256 _value) public returns (bool success)

7function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)

8function approve(address _spender, uint256 _value) public returns (bool success)

9function allowance(address _owner, address _spender) public view returns (uint256 remaining)

Events

1event Transfer(address indexed _from, address indexed _to, uint256 _value)

2event Approval(address indexed _owner, address indexed _spender, uint256 _value)

Copy

Examples

Let's see how a Standard is so important to make things simple for us to inspect any ERC-20 Token Contract on Ethereum.We just need the Contract Application Binary Interface (ABI) to create an interface to any ERC-20 Token. As you cansee below we will use a simplified ABI, to make it a low friction example.

Web3.py Example

First, make sure you have installed Web3.py(opens in a new tab) Python library:

1pip install web3

1from web3 import Web3

2

3

4w3 = Web3(Web3.HTTPProvider("https://cloudflare-eth.com"))

5

6dai_token_addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F" # DAI

7weth_token_addr = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # Wrapped ether (WETH)

8

9acc_address = "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11" # Uniswap V2: DAI 2

10

11# This is a simplified Contract Application Binary Interface (ABI) of an ERC-20 Token Contract.

12# It will expose only the methods: balanceOf(address), decimals(), symbol() and totalSupply()

13simplified_abi = [

14 {

15 'inputs': [{'internalType': 'address', 'name': 'account', 'type': 'address'}],

16 'name': 'balanceOf',

17 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}],

18 'stateMutability': 'view', 'type': 'function', 'constant': True

19 },

20 {

21 'inputs': [],

22 'name': 'decimals',

23 'outputs': [{'internalType': 'uint8', 'name': '', 'type': 'uint8'}],

24 'stateMutability': 'view', 'type': 'function', 'constant': True

25 },

26 {

27 'inputs': [],

28 'name': 'symbol',

29 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}],

30 'stateMutability': 'view', 'type': 'function', 'constant': True

31 },

32 {

33 'inputs': [],

34 'name': 'totalSupply',

35 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}],

36 'stateMutability': 'view', 'type': 'function', 'constant': True

37 }

38]

39

40dai_contract = w3.eth.contract(address=w3.to_checksum_address(dai_token_addr), abi=simplified_abi)

41symbol = dai_contract.functions.symbol().call()

42decimals = dai_contract.functions.decimals().call()

43totalSupply = dai_contract.functions.totalSupply().call() / 10**decimals

44addr_balance = dai_contract.functions.balanceOf(acc_address).call() / 10**decimals

45

46# DAI

47print("===== %s =====" % symbol)

48print("Total Supply:", totalSupply)

49print("Addr Balance:", addr_balance)

50

51weth_contract = w3.eth.contract(address=w3.to_checksum_address(weth_token_addr), abi=simplified_abi)

52symbol = weth_contract.functions.symbol().call()

53decimals = weth_contract.functions.decimals().call()

54totalSupply = weth_contract.functions.totalSupply().call() / 10**decimals

55addr_balance = weth_contract.functions.balanceOf(acc_address).call() / 10**decimals

56

57# WETH

58print("===== %s =====" % symbol)

59print("Total Supply:", totalSupply)

60print("Addr Balance:", addr_balance)

Show all

Copy

Known issues

ERC-20 token reception issue

When ERC-20 tokens are sent to a smart contract that is not designed to handle ERC-20 tokens, those tokens can be permanently lost. This happens because the receiving contract does not have the functionality to recognize or respond to the incoming tokens, and there’s no mechanism in the ERC-20 standard to notify the receiving contract about the incoming tokens. The main ways this issue takes form is through:

  1. Token transfer mechanism
  • ERC-20 tokens are transferred using the transfer or transferFrom functions
    • When a user sends tokens to a contract address using these functions, the tokens are transferred regardless of whether the receiving contract is designed to handle them
  1. Lack of notification
    • The receiving contract does not receive a notification or callback that tokens have been sent to it
    • If the receiving contract lacks a mechanism to handle tokens (e.g., a fallback function or a dedicated function to manage token reception), the tokens are effectively stuck in the contract’s address
  2. No built-in handling
    • The ERC-20 standard does not include a mandatory function for receiving contracts to implement, leading to a situation where many contracts are unable to manage incoming tokens properly

Some alternative standards have come out of this issue such as ERC-223

Further reading

Other fungible token standards

  • ERC-223
  • ERC-777
  • ERC-4626 - Tokenized vaults
back-to-top ↑

Was this article helpful?

ERC-20 Token Standard | ethereum.org (2024)
Top Articles
Understanding the Implications: A Comprehensive Look at the NordVPN Data Breach | SubRosa
Delivered Duty Paid (DDP)
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 6388

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.