This commit is contained in:
writer 2024-10-15 12:26:21 +09:00
parent c2d0866191
commit db37d209ab
58 changed files with 4663 additions and 1043 deletions

View file

@ -0,0 +1,26 @@
## ethereum token standards
<br>
### tl; dr
<br>
* EIP stands for **ethereum improvement proposals**.
* ERC stands for **ethereum request for comments** (technical documents written by ethereum developers for ethereum community).
* each such document contains a set of rules required to implement tokens for the ethereum ecosystem.
<br>
---
### in this dir
<br>
* **[ERC20](erc20.md)**
* **[ERC777](erc777.md)**
* **[ERC721](erc721.md)**
<br>

View file

@ -0,0 +1,67 @@
## ERC20
<br>
* 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 users 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
<br>
* `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
<br>
* 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
<br>
```
contract ERC20 {
function totalSupply() constant returns (uint theTotalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns
(bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns
(uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
```

View file

@ -0,0 +1,42 @@
## ERC721
<br>
* to see the difference between ERC20 and ERC721, look at the internal data structure used in ERC721:
```
mapping (uint256 => address) private deedOwner;
```
<br>
* whereas ERC20 tracks the balances that belong to each owner, with the owner being the primary key of the mapping, ERC721 tracks each deed ID and who owns it, with the deed ID being the primary key of the mapping.
<br>
---
### the ERC721 contract interface specification
<br>
```
interface ERC721 /* is ERC165 */ {
event Transfer(address indexed _from, address indexed _to, uint256 _deedId);
event Approval(address indexed _owner, address indexed _approved,
uint256 _deedId);
event ApprovalForAll(address indexed _owner, address indexed _operator,
bool _approved);
function balanceOf(address _owner) external view returns (uint256 _balance);
function ownerOf(uint256 _deedId) external view returns (address _owner);
function transfer(address _to, uint256 _deedId) external payable;
function transferFrom(address _from, address _to, uint256 _deedId)
external payable;
function approve(address _approved, uint256 _deedId) external payable;
function setApprovalForAll(address _operator, boolean _approved) payable;
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
```

View file

@ -0,0 +1,58 @@
## ERC777
<br>
* an ERC20-compatible interface
* transfer tokens using a send function, similar to ether transfers
* compatible with ERC820 for token contract registration
* allow contracts and addresses to control which tokens they send through a tokensToSend function that is called prior to sending
* enable contracts and addresses to be notified of the tokens' receipt by calling a tokensReceived function in the recipient, and to reduce the probability of tokens being locked into contracts by requiring contracts to provide a tokensReceived function
* allow existing contracts to use proxy contracts for the `tokensToSend and `tokensReceived` functions
* operate in the same way whether sending to a contract or an EOA
* provide specific events for the minting and burning of tokens
* enable operators (trusted third parties, intended to be verified contracts) to move tokens on behalf of a token holder
* provide metadata on token transfer transactions in userData and operatorData fields
<br>
---
<br>
### ERC777 contract interface specification
```
interface ERC777Token {
function name() public constant returns (string);
function symbol() public constant returns (string);
function totalSupply() public constant returns (uint256);
function granularity() public constant returns (uint256);
function balanceOf(address owner) public constant returns (uint256);
function send(address to, uint256 amount, bytes userData) public;
function authorizeOperator(address operator) public;
function revokeOperator(address operator) public;
function isOperatorFor(address operator, address tokenHolder)
public constant returns (bool);
function operatorSend(address from, address to, uint256 amount,
bytes userData,bytes operatorData) public;
event Sent(address indexed operator, address indexed from,
address indexed to, uint256 amount, bytes userData,
bytes operatorData);
event Minted(address indexed operator, address indexed to,
uint256 amount, bytes operatorData);
event Burned(address indexed operator, address indexed from,
uint256 amount, bytes userData, bytes operatorData);
event AuthorizedOperator(address indexed operator,
address indexed tokenHolder);
event RevokedOperator(address indexed operator, address indexed tokenHolder);
}
```