Create your first ERC-20 token
Tags: blockchain, web3, tutorial, ethereum
Published: 2021-11-14 19:03:59

By the end of this post, you would be able to create your first token and mint it on any address you want. we would be using the Avalanche C-Chain.

Before we get started, let's go through the basics.

**What are tokens?**
Tokens can be used represent almost anything in Ethereum, from currencies to points in any online platform.

**What is ERC-20?**
It is a standard that allows developers to build applications in a way that it can be used by other services. It allows tokens to be created exactly the same way another token was created. 

## **Preparation**
Download & Setup  [Metamask](https://metamask.io/)
- Install on your web broswer
- Create a new account or import an existing one
- Configure the Avalanche C-chain testnet(free)

![Metamask](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k00u2gz975m87pd4t36r.png)

Now, Fill the appropriate boxes with correct values.

- Network Name: Avalanche C-Chain
- New RPC URL:
     - Mainnet: https://api.avax.network/ext/bc/C/rpcFuji 
     - Testnet: https://api.avax-test.network/ext/bc/C/rpc
- rpcChainID:
     - Mainnet: 43114
     - Fuji Testnet: 43113
- Symbol: AVAX
- Explorer:
    - Mainnet: https://snowtrace.ioFuji 
    - Testnet: https://testnet.snowtrace.io

- Fund your C-Chain address
*Using Avalanche Wallet*
On the main net, you can use the Avalanche Wallet to transfer funds from the X-Chain to your C-Chain address.
*Using Test Network Faucet*
On the test network, you will the Test Network Faucet. Navigate to https://faucet.avax-test.network/ and paste your C-Chain address.

![AVAX Faucet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zl5ket1ddhk4h4rb9h79.png)
    
### Create your token
For the sake of this post, we'd be using Remix - the online editor  [Click here](http://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.7+commit.e28d00a7.js) 

![Remix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3fpk40rvm7tju7a9qlg.png)

You can choose to delete all existing files in the workspace or ignore them. Create a file and give it any name you want  but make sure the extension is .sol.

Next up is finding a Standard ERC-20 Smart Contract. We of course want to use a well tested open source implementation like the official Consensys or Open Zeppelin implementation. We'd be using the OpenZeppelin standard.
Copy this line and paste into the newly created .sol file.

```import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";```


Once the file is saved, remix automatically imports the github repository into our workspace. 
Locate the ERC20PresetMinterPauser.sol file in the presets which was written by OpenZeppelin according to ERC20 standards with minter functionality. After deploying this file, we will be the owner of the contract and we will be ability to mint the tokens.


![Remix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgiyk699eb2znehbbgjs.png)

** Deploying the contract**
Open the second tab - Solidity Compiler
Check that the Solidity Compiler matches the solidity version written in the file as "pragma solidity...". NB: the compiler's version should be equal or higher than the file's version. Since we are using the OpenZeppelin contract directly from github, you can choose to compile or not. Should you choose to compile, you should have no errors if you did not change anything in the file, or the solidity version is not wrong.

![Remix 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdwbff0554o4nkbx7kfc.png)

Proceed to the third tab - Deploy and Run Transaction. 

- Change the environment to "Injected Web3". A pop-up might show up asing you to connect the account, click connect. After, you should see the account address in the "ACCOUNT" textbox.

We're almost done...
- Right above the Deploy button there is a drop-down menu to select a contract. Select the contract named "ERC20PresetMinterPauser.sol".
- Expand the Deploy text to reveal the Name and Symbol Fields. Here, enter the name and symbol of you token (check the highlighted section).
- Click on Deploy and confirm the pop-ups shown.

We have successfully deployed our token to the avalanche C-Chain, now let us play with it.

Before the copy your transaction hash from the remix console, we will need it soon. 

![Remix 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rli1tf8ebfc2fjzff4v8.png)
 
Paste the transaction hash into the  [explorer] https://testnet.snowtrace.io) (if you're using the mainnet, check the url shared earlier)

![Remix 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cobkgm6jcfvg115503o9.png)



The first one is the wallet address that created the token and the second address is the new token contract address. Now, let’s finish this off by minting some token to our own address.

We are back in Remix and now we will see the contract in "Deployed Contracts". 
You will see a long list of functions provided by the smart contract used, we only need the mint method.

Click the arrow beside it and paste your AVAX address from Metamask, to mint 1000 of your token use "1000000000000000000000" and click transact to finish.

![Remix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t92h6eoxxxtdv45t8how.png)

### Add your token to Metamask
We have to add our token to Metamask in order to see it. Click  "Add Token" button and select "Custom Token" tab.

![Remix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lk447z42604jn1imonkn.png)


Congratulations, you have successfully created your very first ERC-20 token. :)

![Remix IDE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwub7vi4necnh5nwutfu.png)


Catch me on [twitter](https://twitter.com/theangelofpc). :)