ethereum / ethereum-org

[ARCHIVED] ethereum.org website from 2016-2019. See https://github.com/ethereum/ethereum-org-website for current version.
GNU Lesser General Public License v3.0
407 stars 1.39k forks source link

crowsale example issue. #799

Open leochan007 opened 6 years ago

leochan007 commented 6 years ago

function () payable { require(!crowdsaleClosed); uint amount = msg.value; balanceOf[msg.sender] += amount; amountRaised += amount; tokenReward.transfer(msg.sender, amount / price); FundTransfer(msg.sender, amount, true); }

is this correct for crowsale??

 tokenReward.transfer(msg.sender, amount / price);

anyone who wanna buytoken may don't have token at all. how to transfer the token to himself?

samsoft00 commented 6 years ago

I'm currently facing the same issue, crowdsales execution terminate at the point tokenReward.transfer(msg.sender, amount / price); it give me the following error

Are you able to work around it? Please help!

leochan007 commented 6 years ago

@samsoft00 i use open zepplin library. 1.7.0 version. allowancecrowdsale.

https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/emission/AllowanceCrowdsale.sol

leochan007 commented 6 years ago

@samsoft00 create token first. create crowdsale. then u have to approve tokenwallet to crowdsale.

360disrupt commented 6 years ago

I think there are two more issues with the example.

  1. Rounding: e.g. if I have an etherCostOfEachToken = 2 and I send 1 ether to the contract the contract takes the 1 ether as a donation and leaves me without any tokens.

  2. The last person has to buy the exact amount of remaining tokens otherwise the contract will fail.

@leochan007 can you explain how to use the code you posted. On the example of the ethereum homepage, I 1st create a token, 2nd I transfer all the tokens to the crowdSale contract's address, 3rd buyers send ether to the crowdSale contract, 4th after the deadline I need to call safeWithdrawal

How does this change with the allowance, does it solve the problems I mentioned above (I see it has a remainingTokens function)? Many thx