diff --git a/advanced_knowledge/token_standards/erc20.md b/advanced_knowledge/token_standards/erc20.md index 45bcff2..05c6129 100644 --- a/advanced_knowledge/token_standards/erc20.md +++ b/advanced_knowledge/token_standards/erc20.md @@ -2,35 +2,32 @@
-* The ERC20 standard defines a common interface for contracts implementing this token, such that any compatible token can be accessed and used in the same way. +* defines a common interface for contracts implementing this token, such that any compatible token can be accessed and used in the same way. +* a transaction sending ether to an address changes the state of an address. a transaction transferring a token to an address only changes the state of the token contract, not the state of the recipient address. +* one of the main reasons for the success of EIP-20 tokens is in the interplay between `approve` and `transferFrom`, which allows for tokens to not +only be transferred between externally owned accounts (EOA). + - but to be used in other contracts under application specific conditions by abstracting away `msg.sender` as the mechanism for token access control. +* a limiting factor lies from the fact that the EIP-20 `approve` function is defined in terms of `msg.sender`. + - this means that user’s initial action involving EIP-20 tokens must be performed by an EOA. + - if the user needs to interact with a smart contract, then they need to make 2 transactions (`approve` and the smart contract internal call `transferFrom`), with gas costs.
-### ERC20-compliant token contract - -* totalSupply -Returns the total units of this token that currently exist. ERC20 tokens can have a fixed or a variable supply. - -* balanceOf -Given an address, returns the token balance of that address. -* transfer -Given an address and amount, transfers that amount of tokens to that address, from the balance of the address that executed the transfer. - -* transferFrom -Given a sender, recipient, and amount, transfers tokens from one account to another. Used in combination with approve. - -* approve -Given a recipient address and amount, authorizes that address to execute several transfers up to that amount, from the account that issued the approval. +--- -* allowance -Given an owner address and a spender address, returns the remaining amount that the spender is approved to withdraw from the owner. +### ERC20-compliant token contract -* Transfer -Event triggered upon a successful transfer (call to transfer or transferFrom) (even for zero-value transfers). +
-* Approval -Event logged upon a successful call to approve. +* `totalSupply`: Returns the total units of this token that currently exist. ERC20 tokens can have a fixed or a variable supply. +* `balanceOf`: Given an address, returns the token balance of that address. +* `transfer`: Given an address and amount, transfers that amount of tokens to that address, from the balance of the address that executed the transfer. +* `transferFrom`: Given a sender, recipient, and amount, transfers tokens from one account to another. Used in combination with approve. +* `approve`: given a recipient address and amount, authorizes that address to execute several transfers up to that amount, from the account that issued the approval. +* `allowance`: given an owner address and a spender address, returns the remaining amount that the spender is approved to withdraw from the owner. +* `Transfer`: event triggered upon a successful transfer (call to transfer or transferFrom) (even for zero-value transfers). +* `Approval`: event logged upon a successful call to approve.
@@ -38,23 +35,20 @@ Event logged upon a successful call to approve. ### ERC20 optional functions -In addition to the required functions listed in the previous section, the following optional functions are also defined by the standard: - -* name -Returns the human-readable name (e.g., "US Dollars") of the token. - -* symbol -Returns a human-readable symbol (e.g., "USD") for the token. +
-* decimals -Returns the number of decimals used to divide token amounts. For example, if decimals is 2, then the token amount is divided by 100 to get its user representation. +* in addition to the required functions listed in the previous section, the following optional functions are also defined by the standard: + - `name`: returns the human-readable name (e.g., "US Dollars") of the token. + - `symbol`: returns a human-readable symbol (e.g., "USD") for the token. + - `decimals`: returns the number of decimals used to divide token amounts. For example, if decimals is 2, then the token amount is divided by 100 to get its user representation.
--- -### The ERC20 interface defined in Solidity +### the ERC20 interface +
``` contract ERC20 {