Write a smart contract that can issue tokens and transfer tokens Image credit to bitcoinmagazine.com This super simple tutorial will walk you through very basic steps of writing a smart contract that can ISSUE TOKENS, like an real ICO, and transfer tokens. Though it is not ERC20 compatible, which makes it insufficient to do an legal ICO so far. This is still a guide that can get you started pretty fast. Things you need A Google Chrome browser (download ) here A registered account (tutorial by ) Metamask CryptoCompare Basic knowledge about what is a smart contract (tutorial by ) Blockgeeks Go visit the place where you write codes Visit from your Chrome browser, which is a great online compiler that you can write smart contracts, deploy contracts, and interact with contracts. Remix compiler Remix compiler ( ) http://remix.ethereum.org/ Start writing your first smart contract! Today we will be writing a simple smart contract that has : only 4 features Record the token balances of each user Data: Check the token balance of a specific user Method: Issue all the tokens Method: Transfer tokens from one user to the other user Method: Now, in the white box of Remix, delete everything and let’s start from fresh. White box is right there circled by the green border Step 1: Specify the solidity version: pragma solidity ^0.4.21; is the programming language that we use to write smart contract. And we are writing in Solidity right now! Here, we have specify the solidity version to be 0.4.21, with has the compatibility up to 0.4.x (x > 21). Solidity Don’t worry if you cannot understand by this stage. Step 2: Create the contract body: contract Token {// Write more codes here} We create a smart contract with a name “Token”. Step 3: Now we are getting to the first feature. Record the token balances of each user. We need a in the type of to record the balances for each of the users. Data: dictionary mapping // Write this inside the "contract Token" body mapping (address => uint256) private balances; This line declare a variable with the type , which can take an of a user, and return a value of that user’s token balance. So it’s like an that you look for an address to get its corresponding token balance. The type stores a user or a deployed smart contract. The type stands for , which is simply a integer number holder. mapping address uint256 dictionary address uint256 unsigned integer (256 bits) The keyword hides this variable from being accessed externally. The is just the name of the variable we are creating. Lot’s of things to catch up. But I promise you that it will be fun! private balances Step 4: We have completed our very first feature. And now we are moving on to the second cool feature — Check the token balance of a specific user. Method: Please add the following code below the , but still inside the Token contract body: mapping We are creating a with the name . This function asks for a input variable with type that named (which is basically the ). And it a output answer with type uint256 (the of that user). The function is and , which opens to public access and can ONLY check the info from without changing them. function getBalance address _account user returns token balance public constant blockchain Inside the function, we the answer by providing (the address ) with the (user address). It will return the token balance of that specific user . return balances book _account _account Step 5: Now we want to be a bit selfish by storing all the ICO tokens to our own wallet right after the deployment of the smart contract (launch of th ICO). By reaching that, we are now building the third feature — Issue all the tokens. Method: Add the following code below the second feature: This is a function, which will only be triggered once right at the moment of deployment. The name is , which must be the same as the smart contract created. The function takes in with the type of (the issue amount of the tokens! As much as you wish!). Constructor Token _initialSupply uint256 Inside the function, we are setting the of the to be the that I have just set! But who the hack is ? It’s the user address who will be deploying the contract and .. it’s YOU! You now have all the tokens. :) balances msg.sender initial supply msg.sender All the codes we have so far Intermission wrap up Now we have a smart contract that can: Store all the token balances of all the users Check the token balance of a specific user Issue a specific amount of tokens at start and send all to you! Well done! That is super fast huh? We will carry on to finish up the last feature — Transfer tokens from one user to the other user. And show you how we gonna deploy and try out the ICO smart contract via Remix and Metamask. Method: Second guide is ready ! here