Search code examples
tokensoliditycryptocurrencyerc20

What happens if the total balance of tokens exceeds the totalSupply of a token?


As I understand it the totalSupply is just a number for informational purpose.
It doesn't impose a hard limit on the total of all balances, or does it ?

Example:

function transfer(address receiver, uint numTokens) public returns (bool) {
  require(numTokens <= balances[msg.sender]);
  balances[msg.sender] = balances[msg.sender] — numTokens;//Remove This
  balances[receiver] = balances[receiver] + numTokens;
  emit Transfer(msg.sender, receiver, numTokens);
  return true;
}

If I were to remove the line which substracts the balance, the tokens would only appear on the receivers balance, but the senders balance would not change.
If that happens the total tokens in existance would be more than before. Is that true ?
Is my understanding correct, that the balance mapping is just a list of balances (comparable to a C# Dictionary) ?

Are there any implications from this a blockchain programmer hast to watch out for ?


Solution

  • If I were to remove the line which substracts the balance, the tokens would only appear on the receivers balance, but the senders balance would not change.

    That's correct.

    If that happens the total tokens in existance would be more than before.

    Correct for the total sum of existing tokens.

    But - The token standards (ERC-20, ERC-721, etc.) also expect you to calculate the total amount of existing tokens (usually stored in a property named totalSupply). Since your snippet doesn't update this totalSupply, its value would became untrue.

    The total supply is mostly used by blockchain explorers such as Etherscan for statistical purposes (calculating the largest holders of a token, their ownership percentage, etc.).

    Other systems, such as decentralized exchanges or dapps in general, might behave unexpectedly when the totalSupply() output doesn't match the real total supply. But it all depends on their implementation, so there's no general answer.