Understand the ERC-20 token smart contract | ethereum.org (2024)

smart contracts

tokens

solidity

erc-20

Beginner

Understand the ERC-20 token smart contract | ethereum.org (1)jdourlens

Understand the ERC-20 token smart contract | ethereum.org (3)April 5, 2020

Understand the ERC-20 token smart contract | ethereum.org (4)5

minute read

Tip author

0x19dE91Af973F404EDF5B4c093983a7c6E3EC8ccE

One of the most significant smart contract standards on Ethereum is known as ERC-20, which has emerged as the technical standard used for all smart contracts on the Ethereum blockchain for fungible token implementations.

ERC-20 defines a common list of rules that all fungible Ethereum tokens should adhere to. Consequently, this token standard empowers developers of all types to accurately predict how new tokens will function within the larger Ethereum system. This simplifies and eases developers’ tasks, because they can proceed with their work, knowing that each and every new project won’t need to be redone every time a new token is released, as long as the token follows the rules.

Here is, presented as an interface, the functions an ERC-20 must implement. If you’re not sure about what is an interface: check our article about OOP programming in Solidity(opens in a new tab).

1

pragma solidity ^0.6.0;

2

3interface IERC20 {

4

5 function totalSupply() external view returns (uint256);

6 function balanceOf(address account) external view returns (uint256);

7 function allowance(address owner, address spender) external view returns (uint256);

8

9 function transfer(address recipient, uint256 amount) external returns (bool);

10 function approve(address spender, uint256 amount) external returns (bool);

11 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

12

13

14 event Transfer(address indexed from, address indexed to, uint256 value);

15 event Approval(address indexed owner, address indexed spender, uint256 value);

16}

17

Show all

Understand the ERC-20 token smart contract | ethereum.org (5)

Copy

Here is a line-by-line explainer of what every function is for. After this we’ll present a simple implementation of the ERC-20 token.

Getters

1function totalSupply() external view returns (uint256);

2

Returns the amount of tokens in existence. This function is a getter and does not modify the state of the contract. Keep in mind that there are no floats in Solidity. Therefore most tokens adopt 18 decimals and will return the total supply and other results as followed 1000000000000000000 for 1 token. Not every token has 18 decimals and this is something you really need to watch for when dealing with tokens.

1function balanceOf(address account) external view returns (uint256);

2

Understand the ERC-20 token smart contract | ethereum.org (7)

Copy

Returns the amount of tokens owned by an address (account). This function is a getter and does not modify the state of the contract.

1function allowance(address owner, address spender) external view returns (uint256);

2

Understand the ERC-20 token smart contract | ethereum.org (8)

Copy

The ERC-20 standard allows an address to give an allowance to another address to be able to retrieve tokens from it. This getter returns the remaining number of tokens that the spender will be allowed to spend on behalf of owner. This function is a getter and does not modify the state of the contract and should return 0 by default.

Functions

1function transfer(address recipient, uint256 amount) external returns (bool);

2

Understand the ERC-20 token smart contract | ethereum.org (9)

Copy

Moves the amount of tokens from the function caller address (msg.sender) to the recipient address. This function emits the Transfer event defined later. It returns true if the transfer was possible.

1function approve(address spender, uint256 amount) external returns (bool);

2

Understand the ERC-20 token smart contract | ethereum.org (10)

Copy

Set the amount of allowance the spender is allowed to transfer from the function caller (msg.sender) balance. This function emits the Approval event. The function returns whether the allowance was successfully set.

1function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

2

Understand the ERC-20 token smart contract | ethereum.org (11)

Copy

Moves the amount of tokens from sender to recipient using the allowance mechanism. amount is then deducted from the caller’s allowance. This function emits the Transfer event.

Events

1event Transfer(address indexed from, address indexed to, uint256 value);

2

Understand the ERC-20 token smart contract | ethereum.org (12)

Copy

This event is emitted when the amount of tokens (value) is sent from the from address to the to address.

In the case of minting new tokens, the transfer is usually from the 0x00..0000 address while in the case of burning tokens the transfer is to 0x00..0000.

1event Approval(address indexed owner, address indexed spender, uint256 value);

2

Understand the ERC-20 token smart contract | ethereum.org (13)

Copy

This event is emitted when the amount of tokens (value) is approved by the owner to be used by the spender.

A basic implementation of ERC-20 tokens

Here is the most simple code to base your ERC-20 token from:

1pragma solidity ^0.8.0;

2

3interface IERC20 {

4

5 function totalSupply() external view returns (uint256);

6 function balanceOf(address account) external view returns (uint256);

7 function allowance(address owner, address spender) external view returns (uint256);

8

9 function transfer(address recipient, uint256 amount) external returns (bool);

10 function approve(address spender, uint256 amount) external returns (bool);

11 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

12

13

14 event Transfer(address indexed from, address indexed to, uint256 value);

15 event Approval(address indexed owner, address indexed spender, uint256 value);

16}

17

18

19contract ERC20Basic is IERC20 {

20

21 string public constant name = "ERC20Basic";

22 string public constant symbol = "ERC";

23 uint8 public constant decimals = 18;

24

25

26 mapping(address => uint256) balances;

27

28 mapping(address => mapping (address => uint256)) allowed;

29

30 uint256 totalSupply_ = 10 ether;

31

32

33 constructor() {

34 balances[msg.sender] = totalSupply_;

35 }

36

37 function totalSupply() public override view returns (uint256) {

38 return totalSupply_;

39 }

40

41 function balanceOf(address tokenOwner) public override view returns (uint256) {

42 return balances[tokenOwner];

43 }

44

45 function transfer(address receiver, uint256 numTokens) public override returns (bool) {

46 require(numTokens <= balances[msg.sender]);

47 balances[msg.sender] = balances[msg.sender]-numTokens;

48 balances[receiver] = balances[receiver]+numTokens;

49 emit Transfer(msg.sender, receiver, numTokens);

50 return true;

51 }

52

53 function approve(address delegate, uint256 numTokens) public override returns (bool) {

54 allowed[msg.sender][delegate] = numTokens;

55 emit Approval(msg.sender, delegate, numTokens);

56 return true;

57 }

58

59 function allowance(address owner, address delegate) public override view returns (uint) {

60 return allowed[owner][delegate];

61 }

62

63 function transferFrom(address owner, address buyer, uint256 numTokens) public override returns (bool) {

64 require(numTokens <= balances[owner]);

65 require(numTokens <= allowed[owner][msg.sender]);

66

67 balances[owner] = balances[owner]-numTokens;

68 allowed[owner][msg.sender] = allowed[owner][msg.sender]-numTokens;

69 balances[buyer] = balances[buyer]+numTokens;

70 emit Transfer(owner, buyer, numTokens);

71 return true;

72 }

73}

74

Show all

Understand the ERC-20 token smart contract | ethereum.org (14)

Copy

Another excellent implementation of the ERC-20 token standard is the OpenZeppelin ERC-20 implementation(opens in a new tab).

Understand the ERC-20 token smart contract | ethereum.org (15)

Last edit

:

,

Invalid DateTime

Was this page helpful?

Understand the ERC-20 token smart contract | ethereum.org (2024)

FAQs

How do you read Ethereum smart contracts? ›

The best way to view a token's smart contract is through Etherscan, a block explorer and analytics platform built on Ethereum. Block explorers like Etherscan allow users to search and index real-time and historical information about a blockchain.

What is Ethereum smart contract ERC20? ›

One of the most significant smart contract standards on Ethereum is known as ERC-20, which has emerged as the technical standard used for all smart contracts on the Ethereum blockchain for fungible token implementations. ERC-20 defines a common list of rules that all fungible Ethereum tokens should adhere to.

How do ERC20 tokens work? ›

ERC-20 allows developers to create smart-contract-enabled tokens that can be used with other products and services. These tokens are a representation of an asset, right, ownership, access, cryptocurrency, or anything else that is not unique in and of itself but can be transferred.

What is the difference between ETH and ETH ERC20? ›

What's the difference between ETH and ERC20? ETH, or “Ether,” is the native cryptocurrency of the Ethereum network, and is used to facilitate transactions on the Ethereum blockchain. ERC20 is the protocol standard for creating Ethereum-based tokens, which can be utilized and deployed in the Ethereum network.

How to decode ETH data? ›

Decoding an Ethereum Transaction
  1. Seeing and knowing that the contract methods calls are what you expect.
  2. Seeing the parameter types and values that allow you to understand how the contracts work.
  3. Analysing a contract to produce stats on method calls.
  4. Tracking interactions with key addresses.

How do I retrieve data from smart contract? ›

The smart contract address can be fetched from the same page where we get the ABI. We just have to scroll up and see “Contract” written under the “Profile summary.” The smart contract address is written in front of the contract. Note: We also need to establish a connection to the Ethereum node.

What can you do with Ethereum smart contracts? ›

User accounts can then interact with a smart contract by submitting transactions that execute a function defined on the smart contract. Smart contracts can define rules, like a regular contract, and automatically enforce them via the code.

What is the benefit of Ethereum smart contract? ›

Benefits of smart contracts

Once a condition is met, the contract is executed immediately. Because smart contracts are digital and automated, there's no paperwork to process and no time spent reconciling errors that often result from manually filling in documents.

How do ERC20 smart contracts work? ›

An ERC20 token is a standard used for creating and issuing smart contracts on the Ethereum blockchain. Smart contracts can then be used to create smart property or tokenized assets that people can invest in. ERC stands for "Ethereum request for comment," and the ERC20 standard was implemented in 2015.

Can you make money from ERC20 token? ›

You can issue a token in less than 10 minutes, send it and make your very own awesome bounty campaigns and increase your profit drastically with minimal effort. After all, tokens are versatile little things that can be used in many cases — all you need is your own imagination and a Generator to help you!

How do ERC20 tokens gain value? ›

After the public has MyToken, and they start trading it, the price becomes set by what the next buyer is willing to pay. If the next buyer is willing to pay more, then the price will go up. If the next buyer is willing to pay less, then the price will go down. Save this answer.

Can you withdraw ERC20 tokens? ›

Select Tether USDT ERC20 from the Withdrawal section of your PA. Choose the trading account you wish to withdraw from and the amount in USD, as well as your private wallet address; take care to provide this exact or funds may be lost and irrecoverable.

How do I know if my ETH is ERC20? ›

The exchange will make it clear what type of chain they are using; however, one easy way to differentiate between these two is by the way the address is structured. An ERC20 Address only starts with '0' and 'x'. For example: 0xbc6e. A TRC20 Address only begins with a capital 'T'.

Can I swap ERC20 to Ethereum? ›

No, you can only swap tokens that are native to the Ethereum network, such as ETH, ERC-20 tokens or NFTs. You can only swap "wrapped" forms of Bitcoin that live on Ethereum.

How many ERC20 tokens are there on Ethereum? ›

Today there are more than 450,000 ERC-20 tokens on Ethereum including Tether (USDT), Binance USD (BUSD), Polygon (MATIC) and Shiba Inu Coin (SHIB).

How do I track my erc20 transaction? ›

To monitor an ERC-20 token, you need to track its transactions and events on the network. You can use Etherscan or other tools to do this. You can use Etherscan to view your token balance, transfers, holders, and approvals.

How do you read an Etherscan contract? ›

Finding the Project's Contract

Within an NFT project on OpenSea, you can view a single item. Then, under “Details,” you'll find a link to the contract address. This link will take you to Etherscan, which is a blockchain explorer. Essentially, it allows you to view information about the Ethereum blockchain.

How do you read transaction data from Ethereum blockchain? ›

However, to access data stored on the Ethereum Blockchain, there are some existing tools as well. If the data is associated with a transaction, Ethereum (ETH) BlockChain Explorer can be used to view the data. If the data is stored in some smart contracts, the smart contract's interface can be used to read the data.

How do I interact with a smart contract directly? ›

Interact with deployed smart contracts
  1. Perform a read operation. To perform a read operation, you need the address that the contract was deployed to and the contract's ABI. ...
  2. Perform a write operation. To perform a write operation, send a transaction to update the stored value. ...
  3. Verify an updated value.
Aug 8, 2022

How do you read a crypto smart contract? ›

A smart contract can be read by visiting a project's Etherscan (if based on Ethereum) and GitHub page.
...
The sections for decimals, governance, and totalSupply reveal the following information:
  1. YFI is a token with 18 decimals.
  2. YFI has a separate governance contract.
  3. YFI has a maximum total supply of 36,666 tokens.
Sep 1, 2022

Where is smart contract data stored? ›

Smart contracts are executed on blockchain, which means that the terms are stored in a distributed database and cannot be changed. Transactions are also processed on the blockchain, which automates payments and counterparties.

Can you make money writing smart contracts? ›

Smart contract development

You could offer your code for free and earn a share of the profits that are coming from your code. Or you could charge a one-time fee for a specific instance of code. Staking is a way to make money with smart contract development.

What is the most used smart contract on Ethereum? ›

Uniswap V3 has become the most popular Ethereum contract in 2022, ranking first when it comes to total gas used throughout the year.

Which smart contract is best for Ethereum? ›

Hyperledger Fabric is an excellent smart contract platform that has proven itself a really viable Ethereum platform alternative. Co-developed by IBM, it is a permissioned blockchain infrastructure that facilitates the execution of smart contracts or “chain codes”.

What are the two drawbacks of smart contracts? ›

Limitations of Smart Contracts

Changing smart contract processes is almost impossible, any error in the code can be time-consuming and expensive to correct.

How much does an ETH smart contract cost? ›

According to Ethereum's yellow paper, the smart contract platform charges 20000 gas for 256 bits. Storage costs are split between two parties: the creator of a contract, who must pay its initial memory size; and anyone who uses it, which includes anyone sending transactions to or reading information from that contract.

Can you send ETH directly to a smart contract? ›

A smart contract is not able to pull a contract-specified amount of ETH from an address. The amount needs to always be specified and signed by the sender. How to chose the amount depends on the wallet software you're using.

What are the 6 functions of ERC20? ›

ERC20 defines the functions balanceOf , totalSupply , transfer , transferFrom , approve , and allowance .

What is the difference between Ethereum and smart contracts? ›

Ethereum is a decentralized blockchain platform that establishes a peer-to-peer network that securely executes and verifies application code, called smart contracts. Smart contracts allow participants to transact with each other without a trusted central authority.

How much is 1 ERC20 token worth? ›

The live price of ERC20 is $ 0.0105946 per (ERC20 / USD) today with a current market cap of $ 11.96M USD. 24-hour trading volume is $ 377.59 USD.

How much is ERC20 worth per token? ›

The current value of 1 ERC20 is ₹0.86 INR.
...
ERC20 to INR.
AmountToday at 4:55 am
0.5 ERC20₹0.43
1 ERC20₹0.86
5 ERC20₹4.32
10 ERC20₹8.64
4 more rows

How much is my ERC20 token worth? ›

The current price of ERC20 is $0.0105 per ERC20. With a circulating supply of 1,128,632,512.422 ERC20, it means that ERC20 has a total market cap of $11,840,066.75. The amount of ERC20 traded has fallen by $17.73 in the last 24 hours, which is a 86.32% decrease.

Does burning tokens increase value? ›

Coin burning reduces the supply, making tokens of that cryptocurrency scarcer. That scarcity can lead to an increase in price and benefit investors.

What happens to ERC20 tokens if Ethereum fails? ›

They will become invalid and unusable. 95% of ICOs is built on ERC20 and ethereum blockchain. Unless there will be another blockchain that will enable all the tokens to run on these token will become worthless. And yes, more than half of the $37 billion of ETH value depends on ICOs.

Are ERC20 tokens taxable? ›

If you sell ERC-20 tokens as part of a crowdfunding effort or as a utility token, you will also owe capital gains or ordinary income taxes on the sale, depending on the situation.

How do you convert tokens to cash? ›

There are two most common ways to convert crypto to cash. One of them is getting the procedure completed through an exchange or a broker. Deposit your cryptocurrency into an exchange and request a withdrawal in the currency of your choice. The funds will be paid to your bank account.

Can I receive ERC20 tokens in my Ethereum address? ›

You can now send and receive ERC20 tokens. Get started by sending your ERC20 tokens to the Ethereum account of your choice. The token accounts will only appear after the token transaction has been confirmed on the Ethereum blockchain.

Do you need ETH to sell ERC20 tokens? ›

Yes. All ERC20 transactions require Ethereum (ETH) to pay for transactions on the Ethereum network. This means to send an ERC20 token from your Exodus wallet, you will need ETH to pay for the Ethereum network fee, which is also known as gas.

Which Ethereum wallet is ERC20 compatible? ›

Universal. Trust Wallet is the premier mobile ethereum wallet which works with any ERC20, BEP2 and ERC721 tokens. Trust Wallet also supports the main blockchains in the Ethereum ecosystem - Ethereum, Ethereum Classic and Callisto.

Is Coinbase ETH on ERC20? ›

You can use Coinbase Wallet to send and receive supported cryptocurrencies and digital assets such as ERC-20 tokens. Coinbase Wallet supports the following networks: Ethereum, Polygon, Bitcoin, Dogecoin, Litecoin, Stellar Lumens, Ripple, and Solana.

What is the difference between ERC20 and eip20? ›

The main difference between EIPs and ERCs is that EIPs are defining mainly Ethereum Core functions and ERCs are defining decentralised application layer functions and designs. ERC is just one of many categories of EIPs but ERCs are the most used EIPs which is a reason why they are so popular and often discussed.

How do I send ERC20 tokens to Ethereum wallet? ›

Sending ERC-20 tokens is as simple as entering or pasting the recipient's Ethereum wallet address. There are mainly two places you can send your ERC-20 tokens from: a wallet from your centralized exchange (Binance, Coinbase, etc) and a software wallet, also called hot wallet (Metamask, Trust Wallet, etc).

What is the best way to transfer ERC20 tokens? ›

Sending ERC20 tokens is very easy with MetaMask. You just need to paste the ERC20 address, ensure that you have enough ETH to cover the transaction fee, and click the “Send” button.

Can anyone create an ERC20 token? ›

Minting an ERC-20 token is not a particularly difficult task, but traditionally it required a certain level of technical knowledge and understanding of the blockchain. Developers could use a token creation platform, write their own smart contracts, or outsource to a team of developers versed in tokenization.

What is the difference between ETH and ERC20 token? ›

What's the Difference Between ETH and ERC-20? Ether (ETH) is the native token used by the Ethereum blockchain and network as a payment system for verifying transactions. ERC-20 is the standard for creating smart contract-enabled fungible tokens to be used in the Ethereum ecosystem.

What is the most expensive ERC20 token? ›

The market cap of the Ethereum (ERC20) Tokens sector is $ 97.66 billion, representing 10.39% of the total crypto market cap.
...
The rise of ERC-20 tokens.
ERC20 token Name and tickerMarket Cap
Aave (AAVE)$1,046,407,376
Chainlink (LINK)$3,522,283,848
Maker (MKR)$608,293,957
Wrapped BTC (WBTC)$4,657,229,789
6 more rows
Sep 28, 2022

How do you interact with Ethereum smart contracts? ›

Interact with deployed smart contracts
  1. Perform a read operation. To perform a read operation, you need the address that the contract was deployed to and the contract's ABI. ...
  2. Perform a write operation. To perform a write operation, send a transaction to update the stored value. ...
  3. Verify an updated value.
Aug 8, 2022

What code language does ETH smart contract use? ›

Solidity is a statically typed programming language designed for developing smart contracts that run on the Ethereum Virtual Machine (EVM) or compatible virtual machines.

How do I get my money out of Etherscan? ›

To transfer and withdraw funds from a particular address, you must hold the private key to that address. For issues related to your Wallet or Exchange, please contact your wallet provider or exchange service directly as they are in a better position to assist you.

What does Etherscan value mean? ›

Etherscan provides information on the balance of ETH at the address, its current value in US dollars, and the total number of transactions made to and from the address.

How do I read crypto transaction details? ›

How To Read a Cryptocurrency Transaction on a Block Explorer
  1. The Transaction Hash ID. The transaction hash, also known as the Transaction ID, is the identifier of this specific transaction. ...
  2. The Sending Address(es) ...
  3. The Fees. ...
  4. The Receiving Address(es) ...
  5. The Transaction's Status.
6 days ago

How do I know if my ETH transaction is successful? ›

Once your transaction has been picked up and verified by a miner, the transaction is then considered successful and complete. The status on its Etherscan Transaction Details page will now read "Success" and you can expect to see your new ETH/token balance updated on your wallet soon. But wait!

Is Solidity easy to learn? ›

One of the reasons why Solidity is easy to learn is its similarity to other programming languages. If you have experience with JavaScript or C++, you will find the syntax of Solidity quite familiar. Solidity code is also easy to read and understand, thanks to its clear and concise syntax.

What is the best language to learn for smart contracts? ›

For developers looking to jump into Web3 without knowing which blockchain they want to build on or which language they want to learn, Solidity and Vyper are the best languages for exploring how smart contracts work and what kind of developer tooling to look out for.

How long does it take to learn Solidity? ›

Professionals with experience in programming concepts and coding languages can usually learn Solidity in 1-6 months. If you have no programming experience, it may take longer. Beginners can take advantage of platforms like CryptoZombies or other free online courses to build a foundation for advanced classes.

Top Articles
What is Crypto Fund?
Understanding 6 Point Perspective | Termesphere Online Gallery
Enrique Espinosa Melendez Obituary
What Happened To Dr Ray On Dr Pol
Gore Videos Uncensored
1movierulzhd.fun Reviews | scam, legit or safe check | Scamadviser
Top Financial Advisors in the U.S.
Melfme
Stream UFC Videos on Watch ESPN - ESPN
A.e.a.o.n.m.s
Chastity Brainwash
Evangeline Downs Racetrack Entries
Calmspirits Clapper
Nwi Arrests Lake County
Find Such That The Following Matrix Is Singular.
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
Accuweather Mold Count
Ups Print Store Near Me
The Weather Channel Local Weather Forecast
Talk To Me Showtimes Near Marcus Valley Grand Cinema
Gen 50 Kjv
Aes Salt Lake City Showdown
4.231 Rounded To The Nearest Hundred
Taylored Services Hardeeville Sc
Things to do in Pearl City: Honolulu, HI Travel Guide by 10Best
Bj's Tires Near Me
Math Minor Umn
Fedex Walgreens Pickup Times
Most popular Indian web series of 2022 (so far) as per IMDb: Rocket Boys, Panchayat, Mai in top 10
Tamilyogi Ponniyin Selvan
Asian Grocery Williamsburg Va
Chilangos Hillsborough Nj
Craigs List Stockton
Lcwc 911 Live Incident List Live Status
Sun Tracker Pontoon Wiring Diagram
Best Restaurants West Bend
Alpha Labs Male Enhancement – Complete Reviews And Guide
Willkommen an der Uni Würzburg | WueStart
3367164101
Race Deepwoken
Online TikTok Voice Generator | Accurate & Realistic
Craigslist Free Cats Near Me
Diamond Desires Nyc
2000 Fortnite Symbols
28 Mm Zwart Spaanplaat Gemelamineerd (U999 ST9 Matte | RAL9005) Op Maat | Zagen Op Mm + ABS Kantenband
Frank 26 Forum
Bob Wright Yukon Accident
Saw X (2023) | Film, Trailer, Kritik
Honeybee: Classification, Morphology, Types, and Lifecycle
Supervisor-Managing Your Teams Risk – 3455 questions with correct answers
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 6423

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.