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, or 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

Congragulations! 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 below) and press create.

Example

Well done ! 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

Make sure to check out part 2 !