Ethereum
$4,163.03 3.09%
ETH · 190w

Understanding ERC-20 token contracts

Understanding ERC-20 token contracts

Earlier this week the ERC-20 token interface became a formal improvement proposal, freezing the definition. This article takes a look at tokens and explains the features and functions of ERC-20 to provide an understanding of what token contracts are and how developers can work with them.

ERC-20 came about as an attempt to provide a common set of features and interfaces for token contracts in Ethereum, and has proved to be very successful. ERC-20 has many benefits, including allowing wallets to provide token balances for hundreds of different tokens and creating a means for exchanges to list more tokens by providing nothing more than the address of the token’s contract. The benefits of creating a token as ERC-20 compliant is such that very few token contracts today are created any other way.

What is a token contract?

There remains a lot of confusion around what token contracts really are. Essentially, a token contract is a smart contract that contains a map of account addresses and their balances. The balance represents a value that is defined by the contract creator: one token contract might use balances to represent physical objects, another monetary value, and a third the holder’s reputation. The unit of this balance is commonly called a token.

List of addresses and token balances

When tokens are transferred from one account to another the token contract updates the balance of the two accounts. For example, a transfer of 10 tokens from 0x2299…3ab7 to 0x1f59…3492 would result in the balances being updated as shown below:

Transfer of 10 tokens from 0x2299…3ab7 to 0x1f59…3492; changes shown in red

It is possible to change the total supply of a token in two ways, if the token contract allows. The total supply of tokens can be increased by minting new tokens. For example, minting 100 tokens to 0x4ba5…ae22 would result in the balances being updated as shown below:

Minting 100 tokens to 0x4ba5…a...
Continue on medium.com
Recent news