[Ethereum] How to link Standard Token with crowdsale in Zeppelin Solidity

crowdsalesolidity

Hello I am trying to create a crowdsale through zeppelin solidity but the main issue is it doesn't provide a way to link standard token with pre-allocated supply with the crowdsale.

pragma solidity ^0.4.13;

import '../node_modules/zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';
import '../node_modules/zeppelin-solidity/contracts/token/StandardToken.sol';


contract BBTico is Crowdsale  {

    function BBTico(uint256 startTime, uint256 endTime, uint256 _rate, address _wallet) 
    Crowdsale(now, now + 5*60,  5, 0xB1A9B5564071A442909b17f8e9C7288b44aFC014 , 0xefcfbc96dc2adfe35d3fff6b1d9e985066d618ac) 
    {}


}

Crowdsale.sol

function Crowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) {
    require(_startTime >= now);
    require(_endTime >= _startTime);
    require(_rate > 0);
    require(_wallet != 0x0);

    // Already Deployed Standard Token Address on Rinkeby Testnet 
    tokenReward = 0xEfCfbc96dc2aDfe35d3fFF6b1D9E985066D618aC;
    startTime = _startTime;
    endTime = _endTime;
    rate = _rate;
    wallet = _wallet;

  }



// fallback function can be used to buy tokens
  function () payable {
    buyTokens(msg.sender);
  }

function buyTokens(address beneficiary) public payable {
    require(beneficiary != 0x0);
    require(validPurchase());

    uint256 weiAmount = msg.value;
    uint256 accessTime = now;

    // calculate token amount to be created
    uint256 tokens = weiAmount.mul(rate);

    // update state
    weiRaised = weiRaised.add(weiAmount);


 //The code doesn't compile with this function   
tokenReward.transferFrom(0xB1A9B5564071A442909b17f8e9C7288b44aFC014,beneficiary, tokens);
}

Best Answer

As of now, their Crowdsale contract is tightly coupled with the MintableToken. What you would need to do is instead of having your Crowdsale contract inherit from Open Zeppelin's Crowdsale contract, just use their contract as base and replace the use of MintableToken with StandardToken.

On top of my mind you would have to replace the function that instantiates the token contract so instead of MintableToken it uses StandardToken AND the function that gets called when someone buys a token should not call token.mint() anymore and instead move token balances around between the contract and the buyer.

Related Topic