Skip to content

Commit

Permalink
Update erc20.md
Browse files Browse the repository at this point in the history
  • Loading branch information
autistic-symposium-helper authored Sep 4, 2023
1 parent fabb19b commit 3450c80
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions advanced_knowledge/token_standards/erc20.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,53 @@

<br>

* 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.

<br>

### 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).
<br>

* 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.

<br>

---

### 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.
<br>

* 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.

<br>

---

### The ERC20 interface defined in Solidity
### the ERC20 interface

<br>

```
contract ERC20 {
Expand Down

0 comments on commit 3450c80

Please sign in to comment.