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

in kleros •  6 years ago 

So you want to become Ethereum developer but not sure how... Here are some great resources to get you started:

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://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:

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

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

Run the transaction.

Verify on Etherscan minting has succeeded.

reading-contract.png

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

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

Summary

If you spot any issues go to https://github.com/kleros/openiico report an issue and help us buidl 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.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!