Create your own Ethereum Token.
We are all familiar with ICO’s (Initial coin offering) by now. Many projects rake in millions of $ from investors with the promise of a revolutionary technology through smart contracts that will change the world.
Quite often there is only that, a promise, along with a white paper and a website and the MVP will be developed after the crowdsale. At this stage (and many projects may never get past this stage) the ‘revolutionary’ smart contracts all look somewhat similar and offer no functionality but a crowdsale.
In this article we’ll demonstrate how easy it is to actually make your own ERC20 token for the Ethereum blockchain. If you want to take a shortcut through the article you can also use this website: www.generateyourtoken.com .
(This article is for educational purposes only)
Step 1: The ERC20 Interface
In Solidity, the programming language for Ethereum, an interface is a piece of reusable code that defines constraints for functions and events, without implementing the function itself. A contract with the ERC20 interface must have implemented all functions defined in the interface.
Luckily we do not have to write all of this code ourselves and we can just copy it from the following repository: https://github.com/OpenZeppelin/zeppelin-solidity/tree/master/contracts/token
To get started open https://remix.ethereum.org and make two files: SafeMath.sol and ERC20.sol paste in the code below into each of the respective files.
Step 2: Implementing our functions
Great work, our building blocks are almost set. Now we have to implement the functions we have defined in our interface. For this we will combine BasicToken.sol and StandardToken.sol from OpenZeppelin into one file called StandardToken.sol .
Here’s a high level overview of what these functions do:
balanceOf : returns the token balance of an Ethereum address.
transfer : transfers an amount to an address of our choosing.
approve : sets an amount of tokens a specified address is allowed to spend on our behalf
allowance : check how much an address is allowed to spend on our behalf
transferFrom : specify an address to transfer from if we are allowed by that address to spend some tokens.
event Transfer and event Approval will log an output event onto the blockchain.
Step 3: Add your own touch
Great work! That was the hardest part. Now all there’s left to do is specify a name, symbol and supply for our token.
Because we tweaked things a little bit we do not have to actually code this! We can just enter the parameters we want when creating the contract in remix. Next to the create button enter a name, symbol, # decimals and total supply in that order (see example beneath) and press create.
Good stuff! You have succesfuly created your first token. Now you can test the functions by sending tokens to the addresses you’ll find in the dropdown menu next to ‘account’ in remix.
You can also deploy this to one of the test networks if you install Metamask.
The full gist can be found here: https://gist.github.com/anonymous/9eabd0015ca7dd431992a522aa8c51cd