Timeline for Why does the ERC20 Token wiki example subtract the balance of address(0) to calculate total supply?
Current License: CC BY-SA 4.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 15, 2018 at 9:24 | vote | accept | Pascal Precht | ||
Aug 15, 2018 at 9:23 | history | edited | Henk | CC BY-SA 4.0 |
added 321 characters in body
|
Aug 15, 2018 at 9:23 | comment | added | Pascal Precht |
Ah! Now I get it. So this is really just for "just in case somebody will actually burn tokens by making transfers to address(0) in the future, we need to make sure those burned tokens are part of the equation". This makes sense now. Thank you for being patient everyone!
|
|
Aug 15, 2018 at 9:20 | comment | added | Henk |
Correct, this function does not transfer tokens. The function transfer does, though. And with transfer , you can send tokens to any address, including address(0) . This contract considers transfering tokens to address(0) to be the same thing as burning tokens. That's because as the balance of address(0) increases, the value returned by the function totalSupply decreases. To the outside world then, the tokens that were sent to address(0) no longer exist.
|
|
Aug 15, 2018 at 9:15 | comment | added | Pascal Precht |
I appreciate the responsiveness here! I understand that tokens get burned on address(0). I'm sure I'm missing something, but I'm still unsure how one thing relates to the other. Sure sending to that address burns tokens, but we don't send to that address with that code. To me it rather looks like return totalSupply - [whatever_is_in_balances[address(0)]] , we don't really touch address(0) anywhere else in that contract. Sorry for being resistant, I hope it makes sense...
|
|
Aug 15, 2018 at 9:10 | comment | added | Henk |
What JasoonS said. This way of calculating the totalSupply is just to let the outside world know that some tokens are no longer in control of anyone anymore, and therefore, burned.
|
|
Aug 15, 2018 at 9:09 | comment | added | JasoonS | No one knows the private key for 0x0 (the ethereum address), so sending tokens to it is destroying those tokens (so they no longer count to the total supply). | |
Aug 15, 2018 at 9:07 | comment | added | Pascal Precht |
I'm not sure I follow. So totalSupply() is supposed to return the total supply (which is already in _totalSupply . Can you elaborate on why balances[address(0)] is subtracted from it then (to get the total supply we already have even without that subtraction)?
|
|
Aug 15, 2018 at 8:57 | history | answered | Henk | CC BY-SA 4.0 |