0

This is the result of adding 500 tokens to msg.sender

  function addTokens()  internal{
      uint256 _value = 500 ;
      balances[msg.sender]+=_value;

The result

0.000000000000000500
1

It is adding it correctly, you need to take into consideration the decimals which in this case is 18. You would need to assign _value to be 500e18 (500 followed by 18 decimal points). Also, by initializing the variable _value with the amount of tokens you want the function to assign the msg.sender and then adding _value to the balances mapping, this is costing unnecessary gas. You are better of just writing: balances[msg.sender] += 500e18;

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.