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:
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:
- https://faucet.ropsten.be/
- https://faucet.kyber.network/ This faucet will need a verified github account
Input your ethereum wallet address and you’ll be credited with ethereum
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.
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.
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.
Once you hit deploy, MetaMask will prompt you to buy some test ether and submit the transaction. It looks something like this:
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:
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”.
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.
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:
Now anyone can visit your contract address and read the source
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:
Hit Next and Confirm. You should now see all the initial supply
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
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?
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.
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?