The Anatomy of ERC20 (2024)

What’s on the Inside of Ethereum’s Most Popular Contract

Published in

BlockChannel

·

4 min read

·

Sep 30, 2017

--

The Anatomy of ERC20 (3)

Crosspost: This was originally posted by Gerald Nash ⚡️, here. It was reposted to BlockChannel with their permission.

In light of today’s ICO launches, digital token sales during which companies and organizations raise millions of dollars instantly while giving out digital assets, it’s important to recognize the underlying technology that nearly all of these tokens possess: ERC20.

Ethereum Request for Comments 20, or ERC20, is an Ethereum Improvement Proposal introduced by Fabian Vogelsteller in late 2015. It’s a standard by which many popular Ethereum smart contracts abide. It effectively allows smart contracts to act very similarly to a conventional cryptocurrency like Bitcoin, or Ethereum itself. In saying this, a token hosted on the Ethereum blockchain can be sent, received, checked of its total supply, and checked for the amount that is available on an individual address. This is analogous to sending and receiving Ether or Bitcoin from a wallet, knowing the total amount of coins in circulation, and knowing a particular wallet’s balance of a coin. A smart contract that follows this standard is called an ERC20 token.

All of the previously described functionality is able to exist by defining a set of functions that allow a smart contract to emulate a digital token. But how does that work?

ERC20 defines the functions balanceOf , totalSupply , transfer , transferFrom , approve , and allowance . It also has a few optional fields like the token name, symbol, and the number of decimal places with which it will be measured.

Note: This is a concise declaration of an example ERC20 contract.

An overview and example of each field within the contract is as follows.

totalSupply()

Although the supply could easily be fixed, as it is with Bitcoin, this function allows an instance of the contract to calculate and return the total amount of the token that exists in circulation.

balanceOf()

This function allows a smart contract to store and return the balance of the provided address. The function accepts an address as a parameter, so it should be known that the balance of any address is public.

approve()

When calling this function, the owner of the contract authorizes, or approves, the given address to withdraw instances of the token from the owner’s address.

Here, and in later snippets, you may see a variable msg . This is an implicit field provided by external applications such as wallets so that they can better interact with the contract. The Ethereum Virtual Machine (EVM) lets us use this field to store and process data given by the external application.

In this example, msg.sender is the address of the contract owner.

transfer()

This function lets the owner of the contract send a given amount of the token to another address just like a conventional cryptocurrency transaction.

transferFrom()

This function allows a smart contract to automate the transfer process and send a given amount of the token on behalf of the owner.

Seeing this might raise a few eyebrows. One may question why we need both transfer() and transferFrom() functions.

Consider transferring money to pay a bill. It’s extremely common to send money manually by taking the time to write a check and mail it to pay the bill off. This is like using transfer() : you’re doing the money transfer process yourself, without the help of another party.

In another situation, you could set up automatic bill pay with your bank. This is like using transferFrom() : your bank’s machines send money to pay off the bill on your behalf, automatically. With this function, a contract can send a certain amount of the token to another address on your behalf, without your intervention.

Token Name

This is an optional field, but many popular tokens include it so that popular wallets like Mist and MyEtherWallet are able to identify them.

contract MyERCToken {
string public constant name = "My Custom ERC20 Token";
}

Token Symbol

Another optional field used to identify a token, this is a three or four letter abbreviation of the token, just like BTC, ETH, AUG, or SJCX.

contract MyERCToken {
string public constant symbol = "MET";
}

Number of Decimals

An optional field used to determine to what decimal place the amount of the token will be calculated. The most common number of decimals to consider is 18.

contract MyERCToken {
uint8 public constant decimals = 18;
}

The total source code of ERC20 token that we just created can be found here.

In the end, the original ERC20 proposal is rather unappreciated. It opened up avenues for a new set of smart contracts that could be created and distributed in the same fashion as Bitcoin or Ethereum. This proves to be very enticing for young companies, as the entire ERC20 ecosystem is hosted on the Ethereum blockchain, a large pre-existing network of computers. This means that developers and young companies don’t have to attract miners in order to sustain their tokens, something that can save a lot of money. And, these tokens can be hosted on exchanges to be traded like other assets, so investors can easily buy and sell these tokens like more popular currencies.

The Anatomy of ERC20 (2024)
Top Articles
How Guaranteed Income Plans are the safest options amid market volatility
Mortgage Interest Rates | What Is an Interest Rate?
Crete Il Forum
Live2.Dentrixascend.com
Southeast Iowa Buy Sell Trade
The Pope's Exorcist Showtimes Near Emagine Royal Oak
Ark Survival Jellyfish
Zack Fairhurst Snapchat
Tbg95Co
Costner-Maloy Funeral Home Obituaries
City Of Dreams Hosts The Biggest Movie Premiere In American History - Haute Living
Ilsos.gove
Lumos Bill Pay
Aces Fmc Charting
Governor Brown Signs Legislation Supporting California Legislative Women's Caucus Priorities
Christmas concerts, comedy and more: The top 10 things to do in Bay County next week
Knox County 24 Hour List
Umn Pay Calendar
Stewartville Star Obituaries
Graveler Gen 3 Learnset
Rugged Gentleman Barber Shop Martinsburg Wv
Fine Taladorian Cheese Platter
Daftpo
Oscoda Michigan Map: Discover the Charm and Beauty of This Scenic Destination - 200smichigan.com (UPDATE 👍)
Safelite Auto Glass Review: Services And Cost (2024)
Divina Rapsing
Megared Rewards
Metro 72 Hour Extension 2022
Theophylline: MedlinePlus Drug Information
Houses For Sale 180 000
Inb Vaccine Dogs
High School Musical Star Sanborn Daily Themed Crossword
25 Of The Best Crown Tattoos For Men in 2024 | FashionGroomSpot
Pinpoint Recruitment Fort Worth Tx
Www Craigslist Com Corpus Christi
Savannah Riddle Marshall Tx
Restored Republic January 20 2023
Cities An Hour And A Half Away From Me
Craigslist Waldport Oregon
Shamokin Dispensary Menu
Bobby Shmurda Net Worth 2022 Forbes
When to File Your Adjustment of Status Application for Family-Sponsored or Employment-Based Preference Visas: October 2024
Gwdonate.org Login
Carroll Cropper Bridge Traffic Camera
Thespicemustfly
Craigslist Farm And Garden - By Owner Nebraska
Learning The ABCs Of AI Can Bolster Your Career
Jump World Party Prices
Contact us
U-Shaped Cleat Crossword
Lauren Mayberry of CHVRCHES has a brand new solo career — and a sound all her own
Redgifcam
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 5976

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.