Codementor Events

Building your own Ethereum based ECR20 Token in less than an hour

Published May 17, 2020Last updated May 01, 2021
Building your own Ethereum based ECR20 Token in less than an hour

I was applying for a program and a task was given to me to build an ECR20 token in less than 48 hours. This was my first attempt at blockchain development and I didn’t know where to start from. I had knowledge of the cryptocurrency world from a user stand point but not as a developer. I searched around for materials to aid in my task but most were not up to date. This is an up-to-date write up on the steps I took while building this token to help others that are interested in building their own token.

Step 1: Contract code
Download my updated smart contract from the legendary Ethereum unicorn rider, BokkyPooBah, by clicking here. This code will be edited to build your own token

Step 2: Create Ethereum wallet with MetaMask
Download MetaMask chrome extension to generate a wallet. This is going to be the owner of the smart contract. Once you download the extension, go ahead and create a new account protected by a password. Then choose “Ropsten TestNet” from the top left corner. It looks like this:

1*L3wedg6XRbgbSWAMsF3fDg.png

Step 3: Get Ropsten Ethers
You’ll need some test Ethers in your new MetaMask account to finish the creation of the tokens. These two faucets are working at the time of writing this article:

Step 4: Edit the contract code

  • Open the contract you downloaded in your Text Editor e.g VS code, Atom, Sublime etc.
  • Go to Line 3–15 and look at the comment section. Although this is a comment section, this will help you down the track of important information about your token
  • Change Line 4 to the title of your Smart Contract
  • Change Line 6, 120 and 121 to the Ropsten Ethereum address you created in MetaMask
  • Change Line 7 and 116 Symbol to your respective coin name (Keep it short)
  • Change Line 8, 102 and 117 to the name of your token
  • For the decimals and total supply on Line 118 and 119, you can just leave it as it is however I’ll explain it just for visibility. On total supply there are actually a few considerations. First one is that the standard (and max) is 18 decimals, meaning that a coin can be splitted in 18 parts.
  • The second one is that let’s say for example you want to issue 100 tokens, on the total supply part you have to put 100 followed by the number of decimals that you choose.
  • Example if I want to emit 100 tokens, what I will put on total supply is: 100000000000000000000; and so it goes.

1*7gUskZVxM06_rYVVUDpTVw.png

Step 5: Deploy Contract Code on Remix
Now head over to Remix IDE (an online solidity compiler and debugger) and paste the code you just modified.

Screenshot 2021-05-01 at 21.18.26.png

Screenshot 2021-05-01 at 21.04.01.png

Next go to the icon with the checkmark on the image and uncheck “Enable Optimizations” if it’s checked. Also set the compiler version to the version that is indicated at the beginning of your contract code. (Note: Do not use the nightly build).

Now go to the next icon below the icon with the checkmark and click on deploy after selecting <your token name> from the drop down list of contracts.

Screenshot 2021-05-01 at 21.08.57.png

Once you hit deploy, MetaMask will prompt you to buy some test ether and submit the transaction. It looks something like this:

1*51Gg-Kj-0AjS7IbyCvjQyA.png

Just make sure you are on Ropsten TestNet and not on the MainNet and then hit Confirm. Now open up MetaMask again and click on the first transaction. It’ll take you to Etherscan where you can observe the ongoing transaction. It may take up to 30s to confirm the transaction. Once it’s confirmed it looks like the following:

1*0u37y53bjSv56eXUGNVBBw.png

Note the to address in the above transaction page. That's your contract address.

Step 6: Publish and Verify Contract
Click on your contract address. On the new page click “Code”.

1*i4ZnZwImg6M_67OuZojrlw.png

Now click on “verify and publish” link. Once you are taken to the new page, fill up the details such as compiler version, Enable Optimizations etc and paste the solidity source we deployed earlier.

1*HoGiThse6FdFjF2VkoB9pg.png

Make sure the compiler version you choose matches the one you deployed your code against in the first step. Now hit “verify and publish”. If successful, it’ll generate bytecode and ABI as following:

1*zIh0zbRvOTCaE6J8NuL6aA.png

Now anyone can visit your contract address and read the source

1*Np1HbjaHkspJZdfuoTvOlw.png

Step 7: Add token to your wallet
Now that your token has been verified, you should receive all the initial tokens (100000000 in my case) when you add it to your wallet. So, copy the contract address, go to MetaMask -> Add Token -> Custom token and paste the address. It looks like the following:

1*_OUGlTc7MFdPO9cBAdG2CQ.png

Hit Next and Confirm. You should now see all the initial supply

1*mx1lJwqOYpdk6d1ByJFfAw.png

Congrats!!!
You’ve just created your token. Now that you have your tokens, don’t forget to send me some, I would love to see what you have built. Send your brand new token to 0xFEB02D9383C49A8373F88e82EbCecB553c1837bf

Discover and read more posts from Onyebuchi Valentine Ahiwe
get started
post commentsBe the first to share your opinion
John Bishop
2 years ago

One of the best articles I have read in recent years 👍 Apart from making ERC20 tokens what do you think can staking ETH https://p2p.org/networks/ethereum bring a lot of profit? Does it make any sense?

Jonny Dive
2 years ago

Awesome, I am so tempted to create my own token I feel I could easily create a crypto game that would be better then the rest.

Token Novice
2 years ago

To create this as an actual token that can be listed on an exchange, is the process to just repeat everything, but with the ethereum main net selected?

Show more replies