How to Create ERC-20 token on Avalanche C-Chain

Murat Celiktepe
BCISTCenter
Published in
7 min readNov 8, 2020
Avalanche

ERC-20 tokens are the most fundamental and essential concept in Ethereum. As the Avalanche community and the ecosystem are growing, new use cases and projects that are running on Ethereum or different chains would be implemented to Avalanche. The token standard that would be used for the projects is not specific and everyone can create their own standard and own token.

Therefore, we will be creating our own mintable ERC-20 token and will mint it to any address we want. The token will be generated on Avalanche C-Chain and will be accessible on that chain.

The thing we have to mainly consider is that we will deploy a smart contract written with solidity to Avalanche. This is the feature that Avalanche provides us- to be able to deploy any smart contract to the chain and no requirement for a new language specific contract concept to interact. Let’s look at how to create an ERC-20 contract and deploy it to avalanche C-Chain.

The first thing we should set is a metamask wallet.

Metamask Main Network

Click to metamask icon on the browser and select the network drop-down menu. Here we should connect to C-Chain. Click to “Custom RPC”.

New Network

Now, we need to set these boxes with correct values.

Network Name: Avalanche C-Chain

New RPC URL:

ChainID:

  • 0xa868 for Local Testnet
  • 0xa869 for Fuji Testnet
  • 0xa86a for Mainnet

Symbol: C-AVAX

Explorer:

Metamask Main Menu

After setting up all the parameters correctly, we should see this page. For now, we have 0 C-AVAX. “C” refers to C-chain and we have to get some C-AVAX to interact with the network.

Let’s go to avax faucet and paste our address with prefix “C-”.

For example my address is “0xfe8886bec537252040Dff36448C0F104Be635650” ,I need to paste my account address as “C-0xfe8886bec537252040Dff36448C0F104Be635650”

AVAX Faucet

After copy and paste the address here, click request 2.0000 C-AVAX. This test faucet token has no value, it is just for development purposes.

Then check your wallet balance and you should have some test token in your metamask.

Now, we can create our mintable token on Remix. Open Remix on your browser or go to this link.

Solidity

You should view this page. On this page, first, click “SOLIDITY” from “Featured Plugins” and then click the “New File” button. When you click the New File button, you will see a pop-up that requires a file name. You can choose a name or leave the default.

Since we will use an ERC-20 contract from OpenZeppelin, just paste this line to the file and save.

import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/presets/ERC20PresetMinterPauser.sol”;

Solidity — New File

After saving the file, we will see a bunch of files that are imported to remix. This is a remix feature that allows us to import a GitHub contract repository to remix by just giving the URL-Link. with an import statement.

We have ERC20PresetMinterPauser.sol file in the presets. This file is written by OpenZeppelin according to ERC20 standards with minter functionality. After deploying this file, we will be the owner of the contract and will have the authority and ability to mint token how much we want.

Open the second tab which is “SOLIDITY COMPILER” and select the solidity version that matches with the solidity version written in file as “pragma solidity …..”. The version should be equal to or bigger than the file’s version. For example, in my file, “pragma solidity ^0.6.0” is written and the version is 0.6.0. So, in the compiler I solidity version as 0.6.6. After setting up the solidity version click to compile button. If you did not change anything in the file or the solidity version is not wrong, you should not get an error.

Then, let’s jump to the third tab which is DEPLOY & RUN TRANSACTION. Here before deploying our contract, we should change the environment. Click to the environment and select “Injected Web3”. If a pop-up shows up and asks you to connect the account, click to connect. After, you should see the account address in the “ACCOUNT” textbox.

The last thing before the deployment process is to set the contract that will be deployed as a token. Above the Deploy Button, there is a drop-down menu to select a contract. Select the contract named “ERC20PresetMinterPauser.sol”.

Now, here enter the name and symbol of your token. I will name it “test” and the symbol will be “tst”. You can give it a and click to transact button.

After clicking the button, a pop-up will show up and just confirm it.

And then another pop-up, a metamask confirmation, appears. Confirm it.

After confirming all these pop-ups we have deployed our token to avalanche C-Chain. So we can start to interact with it.

We can see our transaction that deployed on avalanche C-Chain via this c-chain explorer.

But firstly, let’s see our transaction hash from the remix console.

After deploying the contract, we should see a log in remix console. When you click to arrow and expand it, a transaction hash will come up. Copy it.

Just paste the transaction hash to the explorer I shared above and press enter.

Here we can see all details about the transaction and token contract.

The first one is my wallet address that creates token and the second address is my token contract address which is named “test”. Now, let’s mint some token to our own address.

Come back to the remix and after deploying, you should be able to see the contract in “Deployed Contracts” section.

Here, we have a bunch of functions that we can use to interact with our token contract. You can check all these methods from OpenZeppelin documentation to learn how to use them. But we will only use the mint method.

Click to arrow beside the mint method to read it.

Enter your address and an amount in WEI. For example, I will mint 1000 tst token so, I entered “1000000000000000000000”

Now we minted 1000 token to our contract, but you should not be able to see the tokens in your metamask wallet. In order to see our own token, we have to add it. On metamask, click to “Add Token” button and select “Custom Token” tab.

Here enter the token address that you can see from explorer as I showed above. Copy and paste it here. Then click on the Next button, you should see 1000 token that you named in your metamask wallet. Also, you can send it to another account via either remix or metamask.

I hope you managed all the steps with no error.

See you in the next article…

Murat CELIKTEPE

LinkedIn → celiktepemurat

Twitter → muratctp

--

--