Skip to content

Instantly share code, notes, and snippets.

@sahilrajput03
Last active November 14, 2022 04:26
Show Gist options
  • Select an option

  • Save sahilrajput03/9e596c7d645f7d5d40e93baae71982c7 to your computer and use it in GitHub Desktop.

Select an option

Save sahilrajput03/9e596c7d645f7d5d40e93baae71982c7 to your computer and use it in GitHub Desktop.

Commentary on ERC20

Source: ethereum.org

  • Methods:
  - name(): OPTIONAL, Returns the name of the token - e.g. "MyToken". ALSO: `function name() public view returns (string)`
  - symbol(): OPTIONAL, Returns the symbol of the token. E.g. “HIX”. ALSO: `function symbol() public view returns (string)`
  - decimals(): OPTIONAL, Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation. ALSO: `function decimals() public view returns (uint8)`
  - totalSupply(): Returns the total token supply. ALSO: `function totalSupply() public view returns (uint256)`
  - balanceOf(): Returns the account balance of an account. ALSO: `function balanceOf(address _owner) public view returns (uint256 balance)`
  - transfer(): Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend. ALSO: `function transfer(address _to, uint256 _value) public returns (bool success)`
  - transferFrom(): Transfers `_value` amount of tokens from address `_from` to address `_to`, and MUST fire the Transfer event. The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. ALSO: `function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)`
  - approve(): Allows `_spender` to withdraw from your account multiple times, up to the `_value` amount. If this function is called again it overwrites the current allowance with `_value`. Clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. ALSO: `function approve(address _spender, uint256 _value) public returns (bool success)`
  - allowance(): Returns the amount which _spender is still allowed to withdraw from `_owner`. ALSO: `function allowance(address _owner, address _spender) public view returns (uint256 remaining)`
  • Events:
- Transfer: MUST trigger when tokens are transferred, including zero value transfers.
event Transfer(address indexed _from, address indexed _to, uint256 _value)

- Approval: MUST trigger on any successful call to approve(address _spender, uint256 _value).
event Approval(address indexed _owner, address indexed _spender, uint256 _value)

Implementations:

  • Openzeppelin Implementation: Click here
  • ConcenSys Implementation: Click here (Disadvantage: They are not gas optimized as much Openzeppelin contracts are bcoz they use unchecked keyword to optimize).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment