For ICO Crowd Sale I have created 2 contracts one is MyToken.sol & other is MyTokenCrowdSale.sol. MyToken.sol creates fixed supply ERC20 tokens.

contract MyToken is DetailedERC20, StandardToken {

    * Init token by setting its total supply
    * @param totalSupply total token supply
    function MyToken(
        uint256 totalSupply
    ) DetailedERC20(
        "My Token",
    ) {
        totalSupply_ = totalSupply;
        balances[msg.sender] = totalSupply;

The other contract MyTokenCrowdSale is a crowdsale contract on which the buyer/beneficiary send ether & in return after verification onlyAdmin transfers corresponding tokens to the buyer.

pragma solidity ^0.4.21;

import "../node_modules/zeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import '../node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol';
import '../node_modules/zeppelin-solidity/contracts/math/SafeMath.sol';

contract MyTokenCrowdSale is Crowdsale, Ownable {
    using SafeMath for uint256;

    //Decimal Facotor
    uint256 private constant decimalFactor = 10**uint256(18);

    // Map of all purchaiser's balances
    mapping(address => uint256) public balances;

    uint256 public tokensIssued;

    ERC20 public tokenReward;

    // Amount raised in PreICO
    // ==================
    // uint256 public totalWeiRaisedDuringPreICO;
    // ===================

    function MyTokenCrowdSale(
        uint256 _rate,
        address _wallet,
        ERC20 _token
    ) Crowdsale(
        tokenReward = ERC20(_token);

    // Token Purchase
    // =========================
    function () external payable {

     * @dev Checks whether the period in which the crowdsale is open has already elapsed.
     * @return Whether crowdsale period has elapsed
    function hasClosed() public view returns (bool) {
        return closed;

     * @dev Closes the period in which the crowdsale is open.
    function closeCrowdsale(bool closed_) public onlyOwner {
        closed = closed_;

     * @dev Overrides parent by storing balances instead of issuing tokens right away.
     * @param _beneficiary Token purchaser
     * @param _tokenAmount Amount of tokens purchased
    function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
        balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
        tokensIssued = tokensIssued.add(_tokenAmount);

     * @dev Deliver tokens to receiver_ after crowdsale ends.
    function withdrawTokensFor(address receiver_) public onlyOwner {
        emit Test("Testing withdrawTokensFor ");

     * @dev Withdraw tokens for receiver_ after crowdsale ends.
    function _withdrawTokensFor(address receiver_) internal {
        uint256 amount = balances[receiver_];
        require(amount > 0);
        balances[receiver_] = 0;
        emit TokenDelivered(receiver_, amount);
       _deliverTokens(receiver_, amount);


My Problem here is I am not able to transfer tokens to the user. It repeteadly says:

Error: VM Exception while processing transaction: revert
    at Object.InvalidResponse

When I debugged the issue , I found the only problem is in the

_deliverTokens(receiver_, amount); 

It is not allowing to send tokens to user. Probably because the MyTokenCrowdSale has no tokens accessible or something.

Need Help!

Your Answer

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

Browse other questions tagged or ask your own question.