create account

Kleros interactive ICO (IICO) - deploy your version and try it out... by genesisre

View this thread on: hive.blogpeakd.comecency.com
· @genesisre ·
Kleros interactive ICO (IICO) - deploy your version and try it out...
So you want to become Ethereum developer but not sure how... Here are some great resources to get you started:

* https://coursetro.com/courses/20/Developing-Ethereum-Smart-Contracts-for-Beginners
* https://www.youtube.com/channel/UCaWes1eWQ9TbzA695gl_PtA

Normally I would not post external links at the beginning of the article but I'm not selling anything - I really want to see the ecosystem growing.

![Screen Shot 2018-05-10 at 14.23.21.png](https://steemitimages.com/DQmTLfoSwo11aQssWuTVmw7b9tm4sA4MFcVqF7shdGpKtUP/Screen%20Shot%202018-05-10%20at%2014.23.21.png)

# https://kleros.io

Past couple of weeks I've been helping with Kleros IICO contract and Dapp - the front end user interface allowing interactions with the smart contract.

The code can be found here:

* https://github.com/kleros/openiico
* https://github.com/kleros/openiico-contract

The instructions below are rather basic, but if you are new to Ethereum, Solidity and the whole ecosystem you'll probably appreciate step-by-step instructions. The intention is to be easy and approachable but you'll still need to show some initiative  - I will not tell you to install `node.js` or `Metamask` - I assume that as a developer interested in crypto you already have some basic understanding in place.

In order to test the https://github.com/kleros/openiico Dapp it might be helpful to deploy your own `iico` contract. 

`git clone https://github.com/kleros/openiico-contract`

We are using Kovan, for me the easier way to get some test Kovan Ether is the faucet: https://gitter.im/kovan-testnet/faucet

You paste your ETH address and a bot sends 5 test ETH shortly after.

We will use Metamask and Remix IDE to deploy the contract.

To get all the files in a single run, we will use a [truffle-flattener](https://www.npmjs.com/package/truffle-flattener)

`npm install truffle-flattener -g`

`truffle-flattener contracts/LevelWhitelistedIICO.sol > output.sol`

Now get the contents of `output.sol` and go to https://remix.ethereum.org/

Constructor parameters:

```
uint256 _startTime, 
uint256 _fullBonusLength, 
uint256 _partialWithdrawalLength, 
uint256 _withdrawalLockUpLength, 
uint256 _maxBonus, 
address _beneficiary, 
uint256 _maximumBaseContribution
```


JavaScript hack to get current timestamp: `((+ new Date()) + "").slice(0, -3)`
Converting date to number, then converting number to string, then removing 3 last digits to have Unix epoch time (as opposed to JavaScript milliseconds)

In my instance I will pass the following parameters:

`1525792200, 86400, 86400, 86400, 2E8, "0x85A363699C6864248a6FfCA66e4a1A5cCf9f5567", "5000000000000000000"`

Note that your initial timestamp and duration of particular phases will differ. Also the beneficiary address is most likely to be different :)

Note that `_maxBonus` is expressed in relation to `uint constant BONUS_DIVISOR = 1E9;`

Note that JavaScript handles large numbers different than Solidity and sometimes you need to apply double quotes.

You can see the deployed contract here: https://kovan.etherscan.io/address/0x3311fff00a0b7553f127b5b25397e12cb268f919#code


# Token creation

We have IICO deployed but we don't have the token! We need to create token now...


```
    function setToken(ERC20 _token) public onlyOwner {
        require(address(token) == address(0)); // Make sure the token is not already set.

        token = _token;
        tokensForSale = token.balanceOf(this);
    }
```


We will create `MintableToken` so that we can mint tokens to the crowdsale address - as you can see in the code above, the amount of tokens for sale is equal to the balance.

Let's do this:

```
pragma solidity ^0.4.19;

import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';

contract KlerosCoin is MintableToken {
    string public name = "KLEROS COIN";
    string public symbol = "KLE";
    uint8 public decimals = 18;
}
```

Save this code in `contracts/KlerosCoin.sol` and then `truffle-flattener contracts/KlerosCoin.sol  > output-coin.sol`

Back to Remix to deploy it.

Here it is deployed `KlerosCoin` contract: https://kovan.etherscan.io/address/0xbddc43642eb2b9307e92d7b7e32c31958081ffb8#code


# Setting the token, setting the whitelister

There are many ways how you can interact with smart contracts. Because we were using Remix IDE we should have easy access to the functions.

First, we will start with mint, the beneficiary is the address of the crowdsale

> Total token supply: 1,000,000,000 PNK
> 16% First Round of Token Sale

Source: https://kleros.io/token-sale

The way how decimals, floating point numbers, and everything works this should be the correct number:
`"160000000000000000000000000"`

*(easy to make a mistake, I'm sorry)*

And the beneficiary: `0x3311fff00a0b7553f127b5b25397e12cb268f919` which is the `iico` address

![interacting-with-contracts.png](https://steemitimages.com/DQmcfcXg2aEVG5A1L5zAm8RX64xkttqgrYnQhWXNLFFkAR8/interacting-with-contracts.png)

Run the transaction.

Verify on Etherscan minting has succeeded.

![reading-contract.png](https://steemitimages.com/DQmZ73ijkX3LGKVkdqx1xx4DehbvVAEJarVuDjA9xyYCQgR/reading-contract.png)

Now set the token to the `iico`. Again will use Remix IDE.

![set-token.png](https://steemitimages.com/DQmcYVu2Lp5g4qLK8AeXRDuiEsaDUrpx2LZLomrLyaNeNNA/set-token.png)

Now set the whitelister - for simplicity the whitelister will be the same account as owner.

Now add to whitelist. Note that the function expects an array, so even if you add a single guy or lady - use square brackets.

# See it on the web

Go to: https://openiico.io/

Put the crowdsales address: `0x3311ffF00A0b7the53f127b5B25397E12CB268F919` *(while still being logged in to Kovan in Metamask)*

After getting yourself with the tutorial, you can place a first bid. If you are the only bidder, the `0.1 ETH` will give you all the tokens!

![single-bid-all-the-tokens.png](https://steemitimages.com/DQmW7nK2fvGZK66jfLXZcZVVtHRzkDd81uKa7qFqLk7GRoC/single-bid-all-the-tokens.png)

# Summary

If you spot any issues go to https://github.com/kleros/openiico report an issue and help us [buidl](https://twitter.com/vitalikbuterin/status/971417459872882690) decentralized future together.

You've guessed correctly, `0x85A363699C6864248a6FfCA66e4a1A5cCf9f5567` is my ETH / ERC20 address and I'm always open to new, exciting project that have potential to meaningfully improve quality of life of every being on this 🌎🌍🌏and beyond.
πŸ‘  
properties (23)
authorgenesisre
permlinkkleros-interactive-ico-iico-deploy-your-version-and-try-it-out
categorykleros
json_metadata{"tags":["kleros","ethereum","solidity","ico","iico"],"image":["https://steemitimages.com/DQmTLfoSwo11aQssWuTVmw7b9tm4sA4MFcVqF7shdGpKtUP/Screen%20Shot%202018-05-10%20at%2014.23.21.png","https://steemitimages.com/DQmcfcXg2aEVG5A1L5zAm8RX64xkttqgrYnQhWXNLFFkAR8/interacting-with-contracts.png","https://steemitimages.com/DQmZ73ijkX3LGKVkdqx1xx4DehbvVAEJarVuDjA9xyYCQgR/reading-contract.png","https://steemitimages.com/DQmcYVu2Lp5g4qLK8AeXRDuiEsaDUrpx2LZLomrLyaNeNNA/set-token.png","https://steemitimages.com/DQmW7nK2fvGZK66jfLXZcZVVtHRzkDd81uKa7qFqLk7GRoC/single-bid-all-the-tokens.png"],"links":["https://coursetro.com/courses/20/Developing-Ethereum-Smart-Contracts-for-Beginners","https://www.youtube.com/channel/UCaWes1eWQ9TbzA695gl_PtA","https://kleros.io","https://github.com/kleros/openiico","https://github.com/kleros/openiico-contract","https://gitter.im/kovan-testnet/faucet","https://www.npmjs.com/package/truffle-flattener","https://remix.ethereum.org/","https://kovan.etherscan.io/address/0x3311fff00a0b7553f127b5b25397e12cb268f919#code","https://kovan.etherscan.io/address/0xbddc43642eb2b9307e92d7b7e32c31958081ffb8#code","https://kleros.io/token-sale","https://openiico.io/","https://twitter.com/vitalikbuterin/status/971417459872882690"],"app":"steemit/0.1","format":"markdown"}
created2018-05-10 13:33:33
last_update2018-05-10 13:33:33
depth0
children0
last_payout2018-05-17 13:33:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,423
author_reputation323,137,051,879
root_title"Kleros interactive ICO (IICO) - deploy your version and try it out..."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id54,956,962
net_rshares594,954,984
author_curate_reward""
vote details (1)