With the latest topics of crypto and blockchain bouncing around left and right. The topic about creating Ethereum token is one of the most searched  topic. Seems like anyone who is touching crypto is getting rich. People are trusting crypto as if its a duck that lays golden eggs but imagine if instead of buying some crypto how about you owned your own currency named after you or after your pet cat. So if you want to create your own cryptocurrency named after your new born kitten. Sit back have patience and lets start creating your own crypto Tokens. If you want to read about all the other topics related to blockchain click here.
If you follow everything as i tell you, you might very well create your own token.

Creating Ethereum Token:

You just need to have some basic knowledge of what token and cryptocurrency for creating Ethereum token. Little experience using Linux and should know the basics of programming.

Difference Between Coin and Token:

Coins:

Altcoins refers to coins that are an alternative to Bitcoin. The majority of altcoins are a variant (fork) of Bitcoin.

Tokens:

Tokens are a representation of a particular asset or utility, that usually resides on top of another blockchain. Tokens can represent basically any assets that are fungible and trade able, from commodities to loyalty points to even other cryptocurrencies!

Ethereum Tokens:

Ethereum Blockchain provides the facility to create your own tokens on top of there blockchain. Ethereum Tokens adhere to a specific standard called the ERC20 Standard. These token can be created to work as a token on there own or work as loyalty points or exclusive membership tokens.

ERC20 Standards:

A standard interface was introduced to allow any token on Ethereum to be re-used by other applications.
The standard includes certain methods that are compulsory for every ERC20 Token to work. These standards has to be followed for creating Ethereum token.

These ERC20 Interface methods helps you decide your total supply of the tokens, the name of the token, the symbol of the token. Lets you store all the balances of accounts. It introduces a standard for sending coins to another address for create an allowance for another account to spend another accounts balance. If you want to get into the detail understanding of all these standards and how to implement them in yourself one by one. You can refer to its link
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
In this tutorial i will make you edit a already written code so that you don’t have to deal with all the compilation bugs and errors.

Setting up the Environment:

So now you understand the basics of it. You know what we are about to create and what methods and functionality will we have for for creating Ethereum token. LETS BEGIN …..
Before we start coding our first smart contract, you need to install the development environment for all of this. Remember this is a ubuntu tutorial done on ubuntu 16.04 LTS.

  1. NodeJS
  2. Truffle
  3. Ganache
  4. Go Ethereum ( Geth)
  5. MetaMask
  6. visual Studio Code

we will be installing all of these one by one for creating Ethereum token.

NodeJS:

The first thing you need for creating Ethereum token is the nodejs package. To check whether you already have nodejs or not open terminal and type  ” nodejs -v “. If you see a nodejs version it means that you have nodejs installed in your system. Other wise you have to run these commands to install nodejs.
First run this command.
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

Then Run this.
$ sudo apt-get install -y nodejs

Now after these two command are done, Again check nodejs version by typing “nodejs -v” . This time it will give you a version. which means that you have successfully installed nodejs.

1538391336446

Truffle:

truffle is a world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.
To install truffle all you have to do is run this command.
$ npm install truffle -g

After installation check the version with ” Truffle version “.

1538392799290

Ganache:

Ganache is your very own personal small ethereum blockchain where you will be for creating Ethereum token. In ganache you can deploy your tokens and run transactions, create blocks by using gas. All of your ganache accounts are pre filled with worthless 100 Ethers.
to install ganache go to  https://truffleframework.com/ganache and downloading the Linux AppImage.
once downloaded go to that directory in your terminal and run the this command
$ chmod a+x ganache-1.1.0-x86_64.AppImage

Your Ganache version might be different than mine depending on when you are performing these steps. Double click on your appimage file that you downloaded and it will run ganache.

1538393127483

Ganache gives you 10 accounts all filled with a 100 ETH for your testing and transactions.

Go Ethereum( Geth):

For creating Ethereum token, the next is installing the geth command that helps you interact with the ethereum main net and ethereum testnet.
To install Geth. all you need to do is to get the geth PPA repository and launch geth stable version from it and you will get geth.

To enable our launchpad repository please run:
$ sudo add-apt-repository -y ppa:ethereum/ethereum

After that you can install the stable version of Go Ethereum:
$ sudo apt-get update
$ sudo apt-get install ethereum

Now again like above once you are done with these commands and they have done there installing. All you have to do is run ” geth version ” and this will show you the geth  version you installed.

1538391476507

Metamask:

Metamask is a browser extension, which is your ethereum wallet that will be your ethereum wallet and a window into the ethereum blokchain. You can connect it to the mainnet, testnet and even ganache and check your coin and account status. Metamask is to ethereum what google chrome is to internet.
To install the extension go to https://metamask.io/

Visual Studio Code:

The last thing you need for creating Ethereum token is a text editor to code and manage your smart contracts. You can use any text editor or an IDE you like. e.g Sublime Text, Notepad++, etc.
I personally use and recommend using visual studio as it can get connected to your github repository and can help you get your code organized and up to date.
Download Visual Studio from https://code.visualstudio.com . Download .deb format. Once downloaded  run the following command on your downloaded file
$ sudo dpkg -i YourVSCodeFile.deb
Install Dependencies.
$ sudo apt-get install -f

Search for Visual studio code in your ubuntu and you will find it installed. Open it go to settings, then extension and then search for solidity package and install it.

1538393845070

Now you are done. Congratulations you have completed setting up your Environment to Develop the ERC20 Token. In the next section we will starting creating the latest project.

Creating a new project:

Now we are going to start our project. To start create a new directory on your desktop or where ever you like. Name that directory what you want your token to be called. In my case i am going to call it AdverceToken and symbol would be AVT you can name it whatever you like. Open terminal and navigate into your newly created directory. Run this command to get your initial files generated.

$ truffle init
$ code ./
to open your project in VS Code.

1538395154220

Truffle would have created some contracts and some migrations for you to start with for creating Ethereum token. The contracts folder is where you will write your smart contracts in solidity. Basically this is where you will write your standards and methods and logic. For now lets leave this and connect this project to the running Ganache.
Open your truffle.js file in VS code and copy and paste this code in the module.exports body.


networks: {
development: {
host: '127.0.0.1',
port: '7545',
network_id: "*"
}

Your file should look like this.

1538395759346

The host and port should be the port and host numbers written on top of your ganache application under RPC SERVER.
Now your empty project is connected to ganache and will use its address and ether for transactions.

Writing you smart contracts:

We saw that truffle created a few folders and files for you to begin with. We edited the truffle.js file for the network. Now we will start creating a new contract file for creating Ethereum token.
Open your terminal in the same directory. In fact always open your terminal in the same project directory.
Type
$ touch contracts/DevToken.sol

Open the newly created file in VS CODE and lets starting coding your token.
For your convenience i am not going to put you through the pain of coding each and every line of this code one by one for creating Ethereum token. So instead what will you do is go to this link copy and paste my code and We will start editing it one by one. All of the methods that are required by the ERC20 Standard have a generic code so just by changing a few lines according to your requirements wont effect the working of the token.

After you paste all the code in your file. Find line 100-110. This is the constructor of this contract here you can see the token name, the symbol, the Total Supply and the decimal value for your coin. Change these values to your desired values.

1538399647493

The next thing you need to do for creating Ethereum token is go to line 83 in the same contract file and change the contract name to your desired token that you set earlier.

1538475020240

Save the file after you are done.

After you wrote your contracts, you need to migrate them to the ganache blockchain using a migration file. To create the migration file for your contract, right click on the migration folder and create a new file named ” 2_deploy_contracts.js “. Deploying the contracts using the migration file is very easy. All you have to do is open the file and write this code.

1538475789642

If you have been already following the tutorial till here so you already know what you have to do here but if you don’t then you have to change the devtoken to your contract name. The contracted file that we created a little while back.

Save everything. You are done with you coding part. Congratulations. Now lets test all of this.

Compiling with Truffle:

Open terminal in your token folder just as we have been doing it since the start and run
$ truffle migrate --reset

It will start compiling and lets hope exactly like me you didn’t break anything and the migration was successful. Let me show you how your output should look.

1538476150260

If you get any errors kindly leave them as comments and i will try to respond as quickly as i can but hopefully you wont have any issues at all.

Interacting with the contracts using truffle console:

After the successful compilation of our migration files and contracts, we will now start interacting with it using the truffle console.
To enter the truffle console type ” $ truffle console “. Now you are in the truffle development environment. Here you can interact with your token and its contracts through a cli, You can check all the accounts that will be connected to your ganache blockchain.

The first thing we do is that you have to deploy an instance of your token and then access all the methods through that. command for that would be.

$ DevToken.deployed().then(function(instance){ devtoken = instance; })

The devtoken that you created is what you will use to interact with your accounts and methods. Lets check the name of your token. Type in truffle
$ devtoken.name()
you will see your token name. Which mean congratulations everything is working perfectly. Don’t worry about the transfer methods and allowance method they work fine as well as all of them were unit tested individually before uploading. ( Unless you changed something :p ).

Here are some of the truffle console commands you can play with.
$ devtoken.symbol()
$ devtoken.decimals()
$ devtoken.totalSupply()
$ devtoken.balanceOf( web3.eth.accounts[0])
$ devtoken.transfer(web3.eth.accounts[1],3434,{from:web3.eth.accounts[0]})

In the above statements you might have seen ” web3.eth.accounts “. web3 is an ethereum library used to accounts on the accounts on the ganache blockchain. If you want to do something with the 10 accounts you can see in ganache, you will use this web3 library.
You can check the address of all the accounts available to you by typing
$ web3.eth.accounts
this will give you all the accounts in ganache. You can check the address shown in terminal and compare it to the one in ganache and you will see that the address are the same as ganache. if you want to access one of those 10 accounts specifically then type ” web3.eth.accounts[0] “. This will give you the first account only and you can see above how i check the balance of the first account in the balanceOf method.

Note: There might be something that you noticed that the balance of account[0] which is the first account is all the tokens that you created. That is because we programmed it in the constructor to give all the initial coins to the account which is deploying and migrating this contract on the blockchain. So the user who deploys the contracts get the initial ownership of all the coins. This is a must to do step for creating Ethereum token.

Connecting Metamask wallet:

The last step of this tutorial is to connect your deployed contracts to the meta mask wallet and checking if you can see your token and do some transactions.

Some steps before you can connect to the meta mask we have to make some changes to our ganache and dev token’s truffle file.

Open ganache and click the settings icon in the top right corner.

1538550386532

Change your port number to 8545 and press restart. One thing to be careful about is that now that ganache has restarted with a new port number so kindly go and change your network port number in your truffle.js file as well to 8545 from 7545.

1538550384036

Save your file. Go to terminal and run ” $ truffle migrate –reset ”  This will compile and save you file and connect it to the new ganache port.

So lets configure your meta mask wallet now for creating Ethereum token. ( i hope you have already installed meta mask extension in your browser. If not then no worries go ahead do it, i will wait for you )

Click on the meta mask fox icon in your browser and lets start configuring. Go through all the agreement accepting.
Meta will ask you for a new password. Instead of doing that click on import seed phrase. Open your ganache and copy the MNEMONIC and paste them in the seed phrase area and give it a new password for your protection. This is how they look by the way.

1538549582229

You will see your meta mask wallet connected to an address that matches the first address on ganache. So you are done. but your ETH are 0 🙁 . The thing is you are checking your account balance on the main ethereum network using this account and this account doesn’t have any ether on the main net. So lets connect meta mask to the ganache blockchain.

Click on the main network drop down and select Localhost:8454 from the list and you should see your Ganache first accounts balance in your wallet. Now you are rich ( Not really 🙁  ).

1538550584134

Go to settings select Add Tokens

1538550656179

Here it requires you to add the token address. Now what is your token address ? don’t panic. When you migrate your token using truffle you are given a token address that points to your token on the blockchain. check your terminal migration output and copy the token address and paste it in meta mask.

1538550752848

after pasting the address it will automatically show you the symbol and the decimals of the tokens which you have provided already. Add this token and it will Go to you wallet with the initial coins.

1538550956306

1538551219400

Your wallet values might differ from many transactions you have done.

You are officially done with for creating Ethereum token on  ERC20 Standards. You can now deploy this token on the ethereum testnet or even make it worth something and deploy it on the ethereum Mainnet. I hope this tutorial was helpful for creating Ethereum token. Please don’t forget to reach out to me if you want any help regarding this.

Solidity V5.0

Solidity is a very new language and with everyday use solidity is updating. Solidity V5.0 has been launched and a few of the methods have been removed or there implementation has been changed from when we wrote this blog. You can check there implementation changes here.


If you want professionals to create and deploy your token on the ERC20 Standards then feel free to contact your blockchain company DevProvider.

Tags: , , , , , ,