How Can We Help?

< Back
You are here:
Print

Use shortcode [ethereum-ico-referral] to display a referral address field.

referral/affiliate

User needs to input her Ethereum account address in the Account field. Referral link would be displayed as a result.

If user has MetaMask account unlocked, the Account field will be hidden, and the MetaMask account address would be used automatically.

Referral link example: https://ethereumico.io?icoreferral=0x476Bb28Bc6D0e9De04dB5E19912C392F9a76535d

User can copy the referral link produced with a special Copy button and send it to her friends. If they buy tokens while opened this referral link, your Crowdsale contract would get a referral address in the Data field.

Your Crowdsale contract should be able to work with it. You can use the Crowdsale Contract and ERC20 Token Development Service to let us do this job for you.

Live demo

Input an Ethereum address like 0x476Bb28Bc6D0e9De04dB5E19912C392F9a76535d into the Account field to see resulting referral link here:

Code examples

You can use this solidity code snippets as a base for your referral/affiliate system implementation.

Put this code to your payable token buy function:


    if(msg.data.length == 20) {
      address referer = bytesToAddress(bytes(msg.data));
      // self-referrer check
      require(referer != address(0x0), "zero-referrer");
      require(referer != msg.sender, "self-referrer");
      uint refererTokens = tokens.mul(2).div(100);
      // bonus for referrer
      token.transfer(referer, refererTokens);
    }

The bytesToAddress function:


  function bytesToAddress(bytes source) internal pure returns(address) {
    uint result;
    uint mul = 1;
    for(uint i; i &lt; 20; i++) {
        result = result.add(mul.mul(uint8(source[19-i])));
        mul = mul.mul(256);
    }
    return address(result);
  }

You can use the Crowdsale Contract and ERC20 Token Development Service to let us do this job for you.

Source: Пишем смарт-контракт Ethereum — это просто: Часть 12 — ICO, реферальная система [ru_RU]

Categories: