Search code examples
soliditycontract

I don't understand why the holder balance is still 0 after he gets tokens


I've been playing with this contract on Ropsten: https://pastebin.com/XPVxPNFv

function distribution(address[] addresses, uint256 _amount) onlyOwner public {       
    uint256 _remainingAmount = _MaxDistribPublicSupply - _CurrentDistribPublicSupply;
    require(addresses.length <= 255);
    require(_amount <= _remainingAmount);
    _amount = _amount * 1e18;

    for (uint i = 0; i < addresses.length; i++) {
        require(_amount <= _remainingAmount);
        _CurrentDistribPublicSupply += _amount;
        balances[msg.sender] += _amount;
        _totalSupply += _amount;
        Transfer(this, addresses[i], _amount);
    }

I don't understand why the holder balance is still 0 after he gets tokens.


Solution

  • As you state in your answer, here you are adding the amount to the address that called or "sent" the transaction, and that is not correct in this case.

    balances[msg.sender] += _amount;

    You should increase the amount of the address that will receive the tokens.

    balances[addresses[i]] += _amount;

    Regards,