ERC20 tokens - Simply Explained - YouTube

Channel: Simply Explained

[0]
We all hear about ERC20 tokens but what are those tokens and most importantly: what are
[6]
they not?
[7]
To start with, let’s quickly go over some basics: ERC20 tokens exist on the Ethereum
[12]
platform and that in itself consists out of a blockchain that is capable of storing transactions
[18]
and a virtual machine that is capable of running smart contracts.
[22]
It’s important to understand that tokens live on the Ethereum blockchain.
[27]
They benefit from its technology.
[28]
They aren’t independent and rely on Ethereum’s blockchain and platform.
[33]
The native currency on the Ethereum network is Ether.
[37]
But besides Ether, it can also support other tokens and these can work like currencies
[41]
but they can also represent shares of a company, loyalty points, gold certificates and so on…
[47]
But we’re running ahead a bit.
[49]
Let’s first look at how tokens come into existence.
[52]
A token can be created by a smart contract.
[55]
This contract is not only responsible for creating tokens but also for managing transactions
[60]
of the token and keeping track of each tokens holder’s balance.
[65]
To get some tokens you have to send some Ether to the smart contract, which will then give
[69]
you a certain amount of tokens in return.
[72]
So when you want to create your own token, you write a smart contract that can create
[76]
tokens, transfer them and keep track of people’s balances.
[80]
That sounds pretty easy but it’s also quite risky.
[83]
For starters, once a smart contract is deployed it cannot be changed anymore, so if you made
[88]
an error you can’t fix it.
[91]
That could be quite catastrophic.
[92]
Imagine a bug inside your contract’s code that causes people to loose their tokens or
[97]
a bug that would allow others to steal tokens.
[100]
And then there is the problem of interoperability.
[103]
Each token contract can be completely different from the other.
[107]
So if you want your token to be available on an exchange, the exchange has to write
[111]
custom code so they can talk to your contract and allow people to trade.
[116]
Same thing goes for wallet providers.
[119]
Supporting hundreds of tokens would be very complex and time consuming.
[122]
So instead, the community proposed a standard called ERC20.
[127]
ERC stands for “Ethereum Request for Comments” and 20 is just the number they assigned to
[132]
a proposal that would create some structure in the wild west of tokens.
[136]
ERC20 is a guideline or standard for when you want to create your own token.
[142]
It defines 6 mandatory functions that your smart contract should implement and 3 optional
[147]
ones.
[148]
To start with you can optionally give your token a name, a symbol and you can control
[153]
how dividable your token is by specifying how many decimals it supports.
[159]
The mandatory functions are a bit more complex: for starters you have to create a method that
[164]
defines the total supply of your token.
[167]
When this limit is reached, the smart contract will refuse to create new tokens.
[172]
Next up is the `balanceOf` method which has to return how many tokens a given address
[176]
has.
[177]
Then there are two transfer methods: `transfer` which takes a certain amount of tokens from
[181]
the total supply and gives them to a user and `transferFrom` which can be used to transfer
[187]
tokens between any two users who have them.
[190]
Finally there is the `approve` and `allowance` methods.
[194]
`Approve` verifies that your contract can give a certain amount of tokens to a user,
[198]
taking into account the total supply.
[201]
The `allowance` method is almost the same except that it checks if one user has a high
[205]
enough balance to send a certain amount of tokens to someone else.
[209]
If you know something about object oriented programming then you can compare ERC20 to
[213]
an interface.
[215]
If you want your token to be an ERC20 token, you have to implement the ERC20 interface
[220]
and that forces you to implement these 6 methods.
[223]
Before there was the ERC20 standard, everyone who wanted to create a token had to reinvent
[228]
the wheel.
[229]
And that meant that each token contract was slightly different and that exchanges and
[234]
wallets had to write custom code to support your token.
[237]
With ERC20 however exchanges and wallet providers only have to implement this code once.
[243]
That’s why exchanges can add new tokens so quickly and why wallets like MyEtherWallet
[248]
have support for all ERC20 tokens, without having to be updated.
[253]
So how easy would be it be to create your own token?
[256]
Well there is a website called TokenFactory that does it all for you.
[259]
You just enter what the total supply of your token should be, how you want to call it,
[263]
how many decimals it should support and what symbol it should have.
[267]
After entering all this, the website creates a token contract for you and adds it to the
[271]
Ethereum blockchain.
[273]
It’s super easy and almost effortless.
[276]
So effortless in fact that the website Etherscan has a list of 36,000 known ERC20 tokens and
[283]
it’s estimated that in 2017 over 4 billion dollars was raised by selling tokens in an
[290]
ICO.
[291]
However these tokens we’re not always clean.
[294]
Some were really overhyped and many people got scammed into purchase tokens that where
[298]
essentially worthless.
[300]
But now we’re getting a bit distracted.
[302]
ERC20 is a great standard that has propelled the use of tokens.
[306]
But ERC20 itself is not perfect.
[309]
It’s only a guideline and people are free to implement the required functions however
[313]
they like.
[315]
That has lead to some interesting problems.
[317]
For instance: to buy some tokens you have to send some ether to the token contract.
[322]
But some people tried sending other ERC20 tokens instead.
[326]
If the contract was not designed with this in mind, it will result in your tokens being
[330]
lost.
[331]
In fact, it was estimated that by December 2017 well over 3 million dollars have been
[337]
lost because of this flaw.
[339]
So to solve this, the community is already working on extending the ERC20 standard with
[344]
the ERC223 standard.
[347]
This warns token creators about these risks and offers some workarounds.
[354]
Let me know what you think about ERC20 tokens in the comments below or send a tweet to @Savjee.
[360]
Thank you very much for watching and don’t forget to subscribe so I see you in the next
[364]
video!