mirror of
https://github.com/autistic-symposium/blockchains-security-toolkit.git
synced 2025-08-22 04:39:43 -04:00
🍟 github vscode is so cool
This commit is contained in:
parent
0931961978
commit
5b8de9dc6d
21 changed files with 16 additions and 1 deletions
31
solidity/token_standards/README.md
Normal file
31
solidity/token_standards/README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
## Token standards
|
||||
|
||||
<br>
|
||||
|
||||
* ERC stands for Ethereum request for comments.
|
||||
* These are 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.
|
||||
* You can say ERC is a specific type of EIP.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### [ERC20](https://github.com/bt3gl-labs/Blockchain-Hacking-Toolkit/blob/main/Solidity-Expert/Token-standards/erc20.md)
|
||||
|
||||
* In the case of ERC20, 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.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### [ERC777](https://github.com/bt3gl-labs/Blockchain-Hacking-Toolkit/blob/main/Solidity-Expert/Token-standards/erc777.md)
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
### [ERC721](https://github.com/bt3gl-labs/Blockchain-Hacking-Toolkit/blob/main/Solidity-Expert/Token-standards/erc721.md)
|
73
solidity/token_standards/erc20.md
Normal file
73
solidity/token_standards/erc20.md
Normal file
|
@ -0,0 +1,73 @@
|
|||
## ERC20
|
||||
|
||||
<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.
|
||||
|
||||
<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.
|
||||
|
||||
* 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.
|
||||
|
||||
* 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
|
||||
|
||||
|
||||
```
|
||||
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);
|
||||
}
|
||||
```
|
||||
|
41
solidity/token_standards/erc721.md
Normal file
41
solidity/token_standards/erc721.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
## 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
|
||||
|
||||
|
||||
```
|
||||
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);
|
||||
}
|
||||
```
|
67
solidity/token_standards/erc777.md
Normal file
67
solidity/token_standards/erc777.md
Normal file
|
@ -0,0 +1,67 @@
|
|||
## 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);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue