You are here:
< Back

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


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:

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.

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( == 20) {
      address referer = bytesToAddres(bytes(;
      // self-referrer check
      require(referer != msg.sender);
      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 = 20; i > 0; i--) {
      result += uint8(source[i-1])*mul;
      mul = mul*256;
    return address(result);

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