After calling this function:

  function WithdrawDividend(uint256 value) public {
    require(value <= _balances[msg.sender]);

    if (_RestrictedFromDividend[address(msg.sender)] <= 0) {
        _SavedDividend[msg.sender] = _balances[address(this)].mul(value).div(100000000);  
        uint256 DividendsToBurn = _SavedDividend[msg.sender].mul(10).div(10000);
        uint256 DividendstoDividend = _SavedDividend[msg.sender].sub(DividendsToBurn);

        _balances[address(this)] = _balances[address(this)].sub(DividendstoDividend).sub(DividendsToBurn);
        _balances[msg.sender] = _balances[msg.sender].add(DividendstoDividend);
        _balances[address(0)] = _balances[address(0)].add(DividendsToBurn);

        _totalSupply = _totalSupply.sub(DividendsToBurn);

        emit Transfer(address(this), msg.sender, DividendstoDividend);
        emit Transfer(address(this), address(0), DividendsToBurn);

        _RestrictedFromDividend[address(msg.sender)] = 1;
        ClaimTime[address(msg.sender)] = now;

    } else {
        emit Transfer(address(this), msg.sender, 0);


Everything successfully works - the balances are updated and the transactions are sent. However, the _RestrictedFromDividend never changes to 1 and I don't understand why. How can I make sure it changes to 1 after this has happened?

  • I usally emit events at the end of the function, try first _RestrictedFromDividend[address(msg.sender)] = 1; ClaimTime[address(msg.sender)] = now; and them emit Events
    – Majd TL
    Jul 20 '19 at 11:16
  • "When" in the transaction you emit events doesn't matter.
    – user19510
    Jul 20 '19 at 18:27
  • @manilpwn You may have to share more details about how you're testing this. Either the whole transaction succeeds or it is reverted, so if you're seeing changes to _balances when you call this function, then there must also be a change to _RestrictedFromDividend.
    – user19510
    Jul 20 '19 at 18:29

Just add an event like

contract yourContract {
  event RestrictedFromDividendEvent(
    uint RestrictedFromDividend

  mapping(address => uint) public _RestrictedFromDividend; // did you put this in public to have a getter

  // in your function

    _RestrictedFromDividend[address(msg.sender)] = 1;
    emit RestrictedFromDividendEvent(

  // end in your function

If it’s does not working there is a side effect somewhere in your execution. But with events like the code above you can log easily your execution flow.

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.