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!
hasClosed()
do, and is it possible it's returningfalse
?require(amount > 0)
. Perhapsamount == 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.