I'd like to make sure I understand how ERC-20 tokens work before trying to make my own. As I understand it from the following code that implements the transfer
function:
function transfer(address receiver, uint numTokens) public returns (bool) {
require(numTokens <= balances[msg.sender]);
balances[msg.sender] -= numTokens;
balances[receiver] += numTokens;
emit Transfer(msg.sender, receiver, numTokens);
return true;
}
The ERC20 contract itself keeps track of who holds which balances. To mint more of a coin, you extend this base contract with a minting contract that inherits from this contract. This minting contract implements the base contract and, via its function implementation, determines how coins may be minted. My questions are:
How does Metamask know who holds which amount of ERC20 tokens? Does Metamask manually set the contract address for well-known ERC20s and use its
balancesOf
function to display the amount each user holds?I want to confirm the ERC20
balances
mapping is the absolute only true ledger of who owns how much of the ERC20 tokenAre there any interfaces for different minting contracts that are popular or widely accepted (like the ERC20 standard)?
Thanks.