[ETHER101] Lession 2: Create a simple Token (Cryptocurrency) with Ethereum
Using the power of Ethereum, you can create your own Token (Cryptocurrency) easily. Basically, a Token implemented in Ethereum has all the advantages of blockchain technique and the encryption process of Ethereum helps secure and verify the transactions of that Token so we can consider a Token is a cryptocurrency.
Cryptocurrencies are digital or virtual currencies that are encrypted (secured) using cryptography.
Token vs Cryptocurrency
So a Token is a Cryptocurrency, but what is the different between them? In short, a Cryptocurrency has only one purpose — it is a unit of currency or medium of exchange, cryptocurrency has its own seperate blockchain. A Token is not only a unit of currency but also has particular asset or utility, token usually resides on top of another blockchain (in this case, it is Ethereum’s blockchain), that’s why building a token is much faster than building a cryptocurrency. Tokens can represent basically any assets that are fungible and tradeable, from commodities to loyalty points to even other cryptocurrencies!
Create a new Token in 10 minutes
I assume that at this point you already go through the lession 1 and has Ethereum Wallet in your PC now.
Everything on Ethereum is based on Smart Contract. So creating a Token is programming a new Smart Contract. Let’s open Ethereum Wallet, go to Contract tab and click Deploy new Contract. Smart contract in Ethereum is writing in Solidity. You may want to learn it at https://solidity.readthedocs.io/.
Now in the Deploy contract screen. Let’s add the below Solidity code to the SOLIDITY CONTRACT SOURCE CODE part:
First we create a map balanceOf to store the balance of our token . Then in the Construction function [8–10] we set the balance of the sender (msg.sender, our address) to the initialSupply , the value initialSupply is the maximum number of token that we have. And finally, the transfer function [13–18] just for transfer the token from the sender to someone. This transfer function is public for everyone so everyone can use this function to send token to each other.
Ok, now we will deploy this token, on the right side of the source code part, select My Bitcoin as the contract to deploy, set the initialSupply to 1000 for testing purpose and then click deploy.
Wait until the deployment is finish, everything will happen the same as we are sending ETHER in lession 1. Then go to the Contract part, you can see a new Custom Contract is created.
Open this contract, you will see something like this:
In the Balance of, let’s input the address of our main account (the account we use to deploy the smart contract). We will see the account is having 1000 token unit
Now we will try to send some token to our second account. In the right tab, choose the transfer function, set the receiver address and value to transfer:
After click the Execute button, wait until the transaction is confirmed, then we can check again the balance of the main account and the second account. We should see the 12 unit of token has been transfered from the main account to the second account now.
Share and Public your Token’s Smart Contract
You are now having a smart contract about your token in the Ethereum Network, now you need to share your smart contract with friends and everyone to help them using the smart contract and the token you have created. To do this, you need two things: The address of the smart contract and the Interface of your smart contract.
In the Smart contract’s view, you can see the address of the smart contract. Click Show Interface button then you can get the JSON Interface of your smart contract.
In your friends’ Ethereum Wallet, go to the Contract part and click Watch Contract and put the address and the JSON interface. After this step, your friend can also access to the smart contract.
You can also verify and publish your contract Source code on Etherscan.io to help everyone access to your smart contract and token, if you are using Testnet of Rinkeby, go to: https://www.rinkeby.io/#explorer
In Etherscan, search the address of your contract, then go to Source Code -> Verify And Publish. You need to input the source code, the contract name, the compiler version exactly as what you use when deploy the contract. One of the most hardest part is Constructor Arguments ABI-encoded, this is the input you use when deploy the contract (which is the initialSupply value). You can get the value on the ABI-encoded part when you deploy your contract (remember to save this value when deploy your contract).
Ok, now you are having your own smart contract and token, congratulations! In the next lession, I will show you how to setup more things on the token to make it can be usable in real business.
Create a cryptocurrency contract in Ethereum
We are going to create a digital token. Tokens in the Ethereum ecosystem can represent any fungible tradable good…