Understanding Tokens on Ethereum

1. The deep meaning of tokens

If you have some knowledge of the Ethereum world, chances are you've heard people talk about tokens — especially ERC20 tokens.

A token in Ethereum is basically a smart contract that follows some common rules - i.e. it implements a standard set of functions that all other token contracts share, such as transfer(address _to, uint256 _value) and balanceOf(address _owner) .

Inside a smart contract, there is usually a mapping, mapping(address => uint256) balances, that keeps track of how much balance each address has.

So basically a token is just a contract that keeps track of who owns how much of that token, and some functions that allow those users to transfer their tokens to other addresses.

2. Why is it important?

Since all ERC20 tokens share the same set of functions with the same name, they can all interact in the same way.

This means that if you build an application that can interact with one ERC20 token, it can also interact with any ERC20 token. This allows you to easily add more tokens to your app in the future without custom coding. You can simply insert the new token contract address, and wow, your app has another token it can use.

One example of this is exchanges. When an exchange adds a new ERC20 token, it really just needs to add another smart contract that talks to it. The user can have that contract send tokens to the exchange's wallet address, and the exchange can then have the contract send the tokens back to the user when they request a withdrawal.

The exchange only needs to implement this transfer logic once, and then when it wants to add a new ERC20 token, it simply adds the new contract address to its database.

3. Ref

(1)https://cryptozombies.io/zh/lesson/5/chapter/1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324416326&siteId=291194637