1

My token is constructed with 100,000,000 supply. Each transaction, 0.007% is burned and a further 0.003% is sent to the contract, making it part of the dividend pool. Here is the transfer function :

function transfer(address to, uint256 value) public returns (bool) {
require(value <= _balances[msg.sender]);
require(to != address(0));

uint256 tokensToBurn = value.div(100000).mul(7);
uint256 tokensToDividend = value.div(100000).mul(3);
uint256 tokensToTransfer = value.sub(tokensToBurn).sub(tokensToDividend);

_balances[msg.sender] = _balances[msg.sender].sub(tokensToTransfer);
_balances[to] = _balances[to].add(tokensToTransfer);

_totalSupply = _totalSupply.sub(tokensToBurn);
_totalDividend = _totalDividend.add(tokensToDividend);

emit Transfer(msg.sender, to, tokensToTransfer);
emit Transfer(msg.sender, address(0), tokensToBurn);
emit Transfer(msg.sender, address(this), tokensToDividend);

return true;

}

After transferring 1 million tokens from Address1 to Address 2, the balances were as such:

Address 1 : 99,000,100 - Incorrect, should be 99,000,000 Address 2 : 999,900 - Correct

Total Supply : 99,999,930 - Correct, suggests that 70 have been burned.

However, you'll notice that the combined balance of the two addresses is 100,000,000, and there is no contract balance, which suggests something has gone wrong. The supply reflects what should be happening, yet total balance is inconsistent.

What have I done wrong?

1 Answer 1

2

What have I done wrong?

WRONG

_balances[msg.sender] = _balances[msg.sender].sub(tokensToTransfer);

CORRECT

_balances[msg.sender] = _balances[msg.sender].sub(value);

Why has nothing been sent to the contract?

I didn't see any code to add balance for contract

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.