i'm trying to test a crowdsale with a already existing token with fixed supply. I have my token already in place and everything is working just fine if i used the account to transfer my tokens but i can not attached to a crowdsale, for token i used the ERC20 standard , maybe i missed something.
my token is something like where StandardToken is the pattern from https://github.com/OpenZeppelin/zeppelin-solidity/tree/master/contracts/token :
contract INOToken is StandardToken, Ownable {
string public constant name = "test";
string public constant symbol = "WOX";
uint8 public constant decimals = 18;
functionINOToken() public {
totalSupply = 300 * 10**6 * 10**18;
balances[owner] = totalSupply; // put all the tokens on the owner
// address
}
function getTotalSupply() public view returns (uint256) {
return totalSupply;
}
}
in this point, token is deployed and is working fine.
Next, i have a very simple contract for simulations of a crowdsale, but i can not use the already existing token, i tried with using an interface and using the token address. What i'm missing, thanks a lot for your help.
interface token {
function balanceOf(address who) public constant returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
function getTotalSupply() public view returns (uint256);
}
contract INOCoinBaseCrowdsale {
using SafeMath for uint256;
// The token being sold
token public tokenReward;
//commented version
// INOCoinToken public tokenReward;
// address where funds are collected
address public wallet;
address public tokenAddress;
// amount of raised money in wei
uint256 public weiRaised;
// crowdsale limit
uint256 public constant CROWDSALE_LIMIT = 1 * (10 ** 6) * (10 ** 18);
event INOCoinTokenPurchase(address indexed purchaser, address indexed
beneficiary, uint256 value, uint256 amount);
function INOCoinBaseCrowdsale(address _wallet, address _tokens) public{
require(_wallet != address(0));
tokenAddress = _tokens;
tokenReward = token(tokenAddress);
wallet = _wallet;
}
// fallback function can be used to buy tokens
function () public payable {
buyTokens(msg.sender);
}
// low level token purchase function
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
require(validPurchase());
uint256 weiAmount = msg.value;
// calculate token to be substracted
uint256 tokens = computeTokens(weiAmount);
require(isWithinCrowdsaleLimit(tokens));
// update state
weiRaised = weiRaised.add(weiAmount);
// send tokens to beneficiary
tokenReward.transfer(beneficiary, tokens);
INOCoinTokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
forwardFunds();
}
// send ether to the fund collection wallet
function forwardFunds() internal {
wallet.transfer(msg.value);
}
// @return true if the transaction can buy tokens
function validPurchase() internal view returns (bool) {
return msg.value != 0;
}
function isWithinCrowdsaleLimit(uint256 _tokens) internal view returns
(bool) {
uint256 soldAmount =
tokenReward.getTotalSupply().sub(tokenReward.balanceOf(tokenAddress));
uint256 soldAmountAfterTransfer = soldAmount.add(_tokens);
return soldAmountAfterTransfer <= CROWDSALE_LIMIT;
}
function computeTokens(uint256 weiAmount) internal view returns (uint256) {
uint256 appliedBonus = 0;
return weiAmount.mul(30).mul(100 + appliedBonus);
}
}
Many thanks in advance