The question is not answered that's why I ask again. Can someone tell me and point out ( correct me) where the problem lies.

Eth has been sent to the crowdsale contract successfully. BalanceOf and amountrised were calculated correctly. Unfortunately, shows with the error on the side of the contributor. enter image description here Why is this happening? What did I miss here? Thank You Robert.

Token Contract https://ropsten.etherscan.io/address/0x6f5c43f62b4b18aa8ed37b42f2804f7049cbe0e9#code

CrowdSale Contract https://ropsten.etherscan.io/address/0x9b94e1894abe2051e6e96bf1b57fe5d3adbbc5aa#code

Environment == Injected Web3 Ropsten MetaMask/Remix

More details are here. Why incorrect number of tokens are sent according to the current rate to the contributor.?

  • Where do you actually transfer tokens in your crowdsale contract? May 30, 2018 at 11:17
  • Hi, tokens was transfer to the token reward address.
    – Robert
    May 30, 2018 at 12:05
  • I mean, where in contract code do you transfer tokens? May 30, 2018 at 12:08
  • I can only add Comment, Look yourself here; // The token being sold ParadiseToken public tokenReward; - line 432 address addressOfTokenUsedAsReward -line 473 tokenReward = ParadiseToken(addressOfTokenUsedAsReward); -486
    – Robert
    May 30, 2018 at 12:15
  • Ok. But I don't see any token transfer functionality in crowdsale contract source code, so token balance can't be changed after investment. May 30, 2018 at 12:38

1 Answer 1


You have no tokens transfer functionality in the crowdsale contract, so tokens balance of the investor address can't be changed after investment. You should modify buy() method and add tokens transfer functionality to it.

function buy ()
        payable public
        require(msg.value >= minContribution);
        uint amount = msg.value;

        // Compute the number of tokens to be rewarded to the sender
        // Note: it's important for this calculation that both wei
        // and PDT have the same number of decimal places (18)
        uint numTokens = amount.mul(rate);

        // --- NEW CODE STARTS HERE -------------------------------------------

        require(tokenReward.transfer(msg.sender, numTokens));

        // --- NEW CODE ENDS HERE ---------------------------------------------

        // update the total amount raised
        amountRaised = amountRaised.add(amount);

        // update the sender's balance of wei contributed
        balanceOf[msg.sender] = balanceOf[msg.sender].add(amount);
        // add to the token balance of the sender
        tokenBalanceOf[msg.sender] = tokenBalanceOf[msg.sender].add(numTokens);

        FundTransfer(msg.sender, amount, true);
        // Check if the funding goal or cap have been reached

In addition to make this code workable you should transfer some tokens cap to the crowdsale contract address. If you don't want to do that and want keep all tokens on some separate ASSET_MANAGER_WALLET address, then you should approve some tokens amount from this address to crowdsale contract address and instead of call transfer function you should call transferFrom function.

require(tokenReward.transferFrom(ASSET_MANAGER_WALLET, msg.sender, numTokens))

  • Thanks for the answer. After adding the code: require(tokenReward.transfer(msg.sender, numTokens));, l can not send eth to crowdsale (out of gas). Try to do the test yourself you will see.
    – Robert
    May 30, 2018 at 14:20
  • Your crowd sale contract does not have any tokens, that's why it cannot send them out. Mar 19, 2019 at 11:17

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.