Tutorial: Ethereum BlockChain Development (5)
Tags: ethereum, blockchain, javascript, tutorial
Published: 2022-02-28 23:17:47

## Part 5: Using ERC20 standard to create a token

> The purpose of building this blog is to write down the detailed operation history and my memo for learning the dApps.
> If you are also interested and want to get hands dirty, just follow these steps below and have fun!~

### Previous Blog
[Tutorial: Ethereum BlockChain Development (1)](https://dev.to/yongchanghe/ethereum-development-log-part-1-deploy-blockchain-and-smart-contract-1a1j)
[Tutorial: Ethereum BlockChain Development (2)](https://dev.to/yongchanghe/ethereum-development-blog-2-53kk)
[Tutorial: Ethereum BlockChain Development (3)](https://dev.to/yongchanghe/tutorial-ethereum-blockchain-development-3-4ple/edit)
[Tutorial: Ethereum BlockChain Development (4)](https://dev.to/yongchanghe/tutorial-ethereum-blockchain-development-4-3poc)


### Intro & Review
Previously We have created tokens that can be used locally when running React dApp, and we can send tokens to recipient account : 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/622adc86rbc0tlr0vn09.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1xr48rdvr2w91cy6twp.png)
 
This time let's take a look at how to use ERC20 standard to create token, which is being used in the real cryptocurrency world.
 
### Preparation 

- **what is token?**

> A token represents a set of rules encoded in a smart contract. Each token belongs to a blockchain address. It’s essentially a digital asset that is stored securely on the blockchain.
> Tokens are most often known to be cryptocurrencies such as Bitcoin or Ether tokens.

- **What is ERC20 token standard?**

> The ERC-20 introduces a standard for Fungible Tokens, in other words, they have a property that makes each Token be exactly the same (in type and value) of another Token. For example, an ERC-20 Token acts just like the ETH, meaning that 1 Token is and will always be equal to all the other Tokens.


## Getting Started

First we shall install [OpenZepplin](https://github.com/OpenZeppelin/openzeppelin-contracts) smart contract library where we will be importing the ERC20 token:
```linux
npm install @openzeppelin/contracts
```

Next, we will create our token. We can go to a website - [Remix IDE](https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.7+commit.e28d00a7.js) and create a  ERC20 token.

> **Remix IDE** is an open source web and desktop application. It fosters a fast development cycle and has a rich set of plugins with intuitive GUIs. Remix is used for the entire journey of contract development as well as act as a playground for learning and teaching Ethereum.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdc0l0dsfdajmuoc2ng0.png)

Let's create a new file called **ExampleToken.sol** in directory **/contracts** in **Workspaces** and add the following code to the new file:
```solidity
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ExampleToken is ERC20 {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        _mint(msg.sender, 100000 * (10 ** 18));
    }
}
```

The constructor allows us to set the token name and the symbol, and the function `_mint` allows us to mint the tokens and set the amount.

> By default, ERC20 sets the number of decimals to 18, so in our `_mint` function we multiply 100,000 by 10 to the 18 power to mint a total of 100,000 tokens, each with 18 decimal places (similarly to how 1 ETH is made up of 10 to the 18 [wei](https://www.investopedia.com/terms/w/wei.asp) (smallest denomination of ether).

Now right click **ExampleToken.sol** and click **Compile**:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3mn0b9vwzyhtdygdo0i.png)
 
Then, click on **Deploy & run transactions**, and choose the contract that we have created, and type your name and symbol that right next to deploy button (e.g. `"Yongchang Token","YT"`), and click **Deploy**:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cjfm23s5a2rc5g17d96.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfivbudgult1sju4ai3v.png)
 

We should see pop-up messages in terminal and should see Deployed Contracts when we scroll down DEPLOY & RUN TRANSACTIONS area and expand our token's name:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn5uacr4t8n3a5qr7vd0.png)

And we can also transfer ERC20 Tokens among the different accounts provided and check account's balance:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ma8rqdy2fs98ps8oszw8.png)

Pretty Cool!

 

### References

https://blockheadtechnologies.com/what-is-a-blockchain-token-is-it-just-cryptocurrency/#:~:text=A%20token%20represents%20a%20set,as%20Bitcoin%20or%20Ether%20tokens.
https://dev.to/dabit3/the-complete-guide-to-full-stack-ethereum-development-3j13
https://ethereum.org/en/developers/docs/standards/tokens/erc-20/