Build your own Cryptocurrency !
Tags: solidity, blockchain, erc, web3
Published: 2023-03-26 06:13:18

Hi all, this is Avinash once again with a small blog post. Let's start this blog with a quick question. Have you ever thought of building your own crypto. Look dont lie and don't forget to drop your answer in the comment box. I am asking this because, this idea came to my mind not only once but a lot of times. So, in this post lets do the same. **Lets create our own crypto.**

So, for building our crypto we will be using ERC20 smart contract. For those who dont know the difference between a Coin and a ERC20 token, read carefully the upcoming content. 

- **Difference between ERC20 Token and a Coin**

The main difference between a coin and an ERC20 token is that coins are standalone currencies, whereas ERC20 tokens are created and operate on the Ethereum blockchain.

Coins have their own independent blockchain network and are often designed to serve as a currency or a means of value transfer. Examples of coins include Bitcoin, Litecoin, and Ripple.

On the other hand, ERC20 tokens are created using the Ethereum blockchain and are subject to the rules and protocols of the Ethereum network. 

I know you did'nt understand. So, in simple terms coins are those which is built from very scratch. They can have their own blockchain network but on the other hand ERC20 tokens are like set of instructions or we can say a protocol which runs only on the ethereum blockchain in form of a smart contract. There are many ERC20 smart contracts out there in the market. The programer can import it, override it and build his or her own's digital asset. 

And this is what we are exactly going to do in this blog post to build our crypto. 

- **Building our Token**

As I said there are many ERC20 smart contracts out there in the market. But for this post we gonna use Open Zeppelin. You read it more about it [here](https://www.openzeppelin.com/).

I think I am boring you know. So, lets start the coding aspect of this blog. But if have understood the above concepts you will have some upperhand than others but if you did'nt you can still continue. _Code speaks more than the theory_ - this is what I believe. With this said lets start. 

I am calling my token as AviToken. Yeah you got it right it is coming from my name Avinash. And for the smybol I am using AVT, just ethereum use ETH, the same way. You are free to use your name and symbol.

```
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// This the open zeppelin's ERC20 Tokens smart contract. 
// And this how we import any contract in solidity using import keyword.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";


// Its time to override some of the properties of this contract.
// How to do that - simple using 'is' keyword
contract AviToken is ERC20 {

    // creating the constructor so that we can pass our initial supply 
    // of the tokens at the time of deployment.

    // again calling ERC20 contracts constructor to give the name and the symbol of the token
    constructor(uint256 _initialSupply) ERC20("AviToken", "AVT") {

        // upto this everything is correct and this will work absolutely fine. 
        // But next we have to tranfers all of the tokens to the author of this contract 
        // lets do this.

        _mint(msg.sender, _initialSupply);

        // _mint function will help us to do the same
        // basically we are telling to the code that hey just put all of those supply of tokens
        // to the address of the author (msg.sender ---> gives address of the current user)
        // at the time of the constructor calling user will be the author

        // and yes you are done.
    }
}
```
Try running the above code on the [remix ide](https://remix.ethereum.org/). It will look something like this. 

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

Deploy it using the ethereum symbol showing in the side bar. 

_**Point to be noted : We will be giving values in WEI i.e 1 = 10^18 Wei**_

So, lets say if we want to have one million tokens as the intial supply then we have to write it like this : 1000000,000000000000000000

Like this, 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90b42auikekyzrsz95qo.png)

Now we have the contract deployed and congratulations to you. You have successfully created your first ever crypto currency. 

Now you can interact with this contract. That is you can transfer tokens from one account to another. Using the UI buttons given by the remix ide. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffr3bhgeyfrr1c2jneo6.png)

That is for today. Hope you guys enjoyed learning with me. And please drop your comments, questions or anything you want to share below.