0

Why does this keep returning 0? And yes, it is above the claimtime. It does it for every address. I don't know what's wrong?

function ViewDividendOwed(address _addr) public view returns (uint256) {
  uint256 _SavedDividend = _balances[address(this)].mul((_balances[msg.sender]).div(_totalSupply));  

  if (ClaimTime[_addr] + 2 minutes <= now) {
    return _SavedDividend;
  }
  else {
    return 0;
  }
}
  • Please include ALL the relevant code (an only the relevant code). What is ClaimTime? Where and how is ClaimTime[_addr] initialized? What is the value of _balances[address(this)] and _balances[msg.sender] and _totalSupply when you call the function? We're not supposed to guess all of that! – goodvibration Oct 13 at 12:45
  • Are you in ganache? – Majd TL Oct 13 at 14:09
1

In your code you are making the division first. My guess is that _totalSupply is larger than any balance so solidity will truncate the result to 0.

uint256 _SavedDividend = _balances[address(this)].mul(
    (_balances[msg.sender]).div(_totalSupply)
);

You have to multiply first and then divide.

uint256 _SavedDividend = (
    _balances[address(this)].mul(_balances[msg.sender])
).div(_totalSupply);
  • This was spot on! Thanks so much – manilpwn Oct 14 at 3:35

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.