0

I'm deploying either token and crowdsale without problems, the crowdsale contract its based on the openzeppelin PostDeliveryCrowdsale.

Crowdsale:

contract PorrolhoTokenCrowdsale is PostDeliveryCrowdsale {

    constructor(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _goal, ERC20 _token) public
    Crowdsale(_rate, _wallet, _token)
    TimedCrowdsale(_openingTime, _closingTime)
    {

    }

}

PostDeliveryCrowdsale:

contract PostDeliveryCrowdsale is TimedCrowdsale {
  using SafeMath for uint256;

  mapping(address => uint256) public balances;

  /**
   * @dev Withdraw tokens only after crowdsale ends.
   */
  function withdrawTokens() public {
    require(hasClosed());
    uint256 amount = balances[msg.sender];
    require(amount > 0);
    balances[msg.sender] = 0;
    _deliverTokens(msg.sender, amount);
  }

  /**
   * @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);
  }

}

I can buy tokens, but when i call the withdrawTokens() function its throwling a error. The balances mapping of the crowdsale contract returns the token amount that i already buyed.

Any idea will be appreciated!

3
  • 1
    Just a guess, but what does hasClosed() do, and is it possible it's returning false?
    – user19510
    Commented Aug 15, 2018 at 4:29
  • unfortunately no, crowdsale.hasClosed.call() = true Commented Aug 15, 2018 at 23:14
  • 1
    Okay, next candidate is require(amount > 0). Perhaps amount == 0. If that's not it, then presumably _deliverTokens(msg.sender, amount) is failing, but I don't see the code for that function, so only you know how that might fail.
    – user19510
    Commented Aug 16, 2018 at 0:31

1 Answer 1

1

I found the problem! I had to transfer the balance (tokens) of the token contract to the crowdsale contract. Okay, I recognize a noob error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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