1

I have your latest version of contracts and almost same example like yours in the Github https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/examples/SampleCrowdsale.sol - I use Ganache for testing on MAC os. And the contract work only when I comment the line

function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
    //token.transfer(_beneficiary, _tokenAmount);
  }

if this is not commented I got a runtime error and revert.

My simple code is as follow:

TOKEN

pragma solidity ^0.4.18;

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

/**
 * The LeonardianToken contract does this and that...
 */
contract LeonardianToken is MintableToken {

    uint256 public constant INITIAL_SUPPLY = 10000;


    string public constant name = "Leonardian"; // solium-disable-line uppercase
    string public constant symbol = "LEON"; // solium-disable-line uppercase
    uint8 public constant decimals = 18; // solium-disable-line uppercase
}

CONTRACT:

pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol';
import "zeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import './LeonardianToken.sol';

contract LeonardianCrowdsale is Crowdsale {

    function LeonardianCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet, MintableToken _token) public 
    Crowdsale(_rate, _wallet, _token)
    // TimedCrowdsale(_startTime, _endTime)
    {

    }
}

MIGRATION (without any errors):

var LeonardianCrowdsale = artifacts.require("./LeonardianCrowdsale.sol");
var LeonardianToken = artifacts.require("./LeonardianToken.sol");

module.exports = function(deployer) {

  deployer.deploy(LeonardianToken).then(function () {

    const startTime = Math.round((new Date(Date.now() - 86400000).getTime())/1000); // Yesterday
    const endTime = Math.round((new Date().getTime() + (86400000 * 20))/1000); // Today + 20 days
    var exchangeRate = 1; // 1 LEON = 0.0025 ETH or 1 ETH = 400 LEON

    deployer.deploy(LeonardianCrowdsale, 
        startTime, 
        endTime,
        exchangeRate, 
        "0x627306090abaB3A6e1400e9345bC60c78a8BEf57", // Replace this wallet address with the last one (10th account) from Ganache UI. This will be treated as the beneficiary address. 
        LeonardianToken.address
      );
  });

};

Can you help me what I`m doing wrong?

SOLUTION

As mentioned ERC20 _token = new LeonardianToken(); must be instanced in the Crowdsale contract and an important thing to work everything after this is to change your migration a little bit

return deployer
    .then(() => {
        return deployer.deploy(Token);
    })
    .then(() => {

        return deployer.deploy(
            Crowdsale,
            startTime,
            endTime,
            exchangeRate,
            "wallet",
            Token.address
        );
    })
    .then(() => {

        var token = Token.at(Token.address);

        token.transferOwnership(Crowdsale.address);
    });
1

The token must be deployed separate from Crowdsale and to be instanced in the Crowdsale

pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol';
import "zeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import './LeonardianToken.sol';

contract LeonardianCrowdsale is Crowdsale {

    ERC20 _token = new LeonardianToken();

    function LeonardianCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet, MintableToken _token) public 
    Crowdsale(_rate, _wallet, _token)
    // TimedCrowdsale(_startTime, _endTime)
    {

    }
}
  • I run into this same issue. How do you get the address of this deployed token externally, and make sure its the correct instance? – Inn0vative1 Apr 25 '18 at 5:02
  • Actually I just tried this solution. It appears to work because it doesn't throw the solutoin, but doesn't actually solve the issue. This is because the instance of the deployed contract is not the same as the instance created in the crowd sale file. So calling withdrawTokens doesn't throw an exception but it also doesn't transfer the tokens correctly. – Inn0vative1 Apr 25 '18 at 5:30
  • I add the right solution to the question – Martin Tonev Apr 25 '18 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.