ERC-20.sol

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol

Variable Definitions:

_balances mapping

  • tracks token holdings of each address

  • private: it can only be accessed within this contract.

    • Contracts deriving from it, cannot access this mapping.

_allowances mapping

--> mapping(address => [address, uint])

  • tracks token allowances of each address.

  • for wallet A, what is the allowance set for a specific address, e.g. UniSwap,

  • Supply parameters as such: _allowances[owner][spender];

Note that anyone can query any address’ allowance, as all data on the blockchain is public. It is important to understand that allowances are “soft”, in that both individual and cumulative allowances can exceed an address’ balance.

In the approval table shown above, for example, the holder 0x2299…3ab7 has approved a transfer of up to 500 tokens but their balance as seen previously is only 90 tokens. Any contract using allowance() must additionally consider the balance of the holder when calculating the number of tokens available to it.

Last updated