1

Can someone give me a hint or correct what is wrong with the code. Maybe it is obvious where the error is but I do not see it and I'm stuck. What to do next ?. The code is here: https://ropsten.etherscan.io/address/0xc3ec072c279043ad2e56f4b5683b78337ed614d9

function () payable public {  }

function buy () payable public whenNotPaused beforeDeadline afterStartTime saleNotClosed {
    require(msg.value >= minContribution);

    // Update the sender's balance of wei contributed and the amount raised
    uint amount = msg.value;
    uint currentBalance = balanceOf[msg.sender];
    balanceOf[msg.sender] = currentBalance.add(amount);
    amountRaised = amountRaised.add(amount);

    // 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);

    // Transfer the tokens from the crowdsale supply to the sender
    if (tokenReward.transferFrom(tokenReward.owner(), msg.sender, numTokens)) {
        FundTransfer(msg.sender, amount, true);
        // Check if the funding goal or cap have been reached
        // TODO check impact on gas cost
        checkFundingGoal();
        checkFundingCap();
    }
    else {
        revert();
    }
}

what to do to fix it ? (Remix Ropsten does not update a sender balance of).

Any help is very much appreciated.Robert

  • Where do you check the updated balance? – Gabe May 4 '18 at 12:19
  • Hi, I'm using Remix to call balanceOf and the amount rised after I'd sent some ethers to crowdsale contract , but no update of balance. Any a hint ? Robert – Robert May 4 '18 at 12:33
0

I think the issue lies in the fact that the function function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } returns a value out of the mapping balances but you are using and updating the mapping named balanceOf. You could create a new function that returns balanceOf[msg.sender] to check if it works.

  • Hello Gabe, I see You reffering to the line 171 in the contract.(contract BasicToken). contract ERC20Basic line 125 has got too -function balanceOf(address who) public view returns (uint256); If you have something on your mind how the function should looks like please enlightme me ! I'm not programmer. I tried to add the following line in my buy function; balanceOf[msg.sender] = balanceOf[msg.sender].add(amount); Unfortunately without success. – Robert May 5 '18 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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