added changes and moved method description above the func declaration

This commit is contained in:
Fabian Vogelsteller 2017-05-17 10:51:09 +02:00 committed by Hudson Jameson
parent 0a051c820c
commit 20706fb8e2
1 changed files with 41 additions and 27 deletions

View File

@ -1,10 +1,11 @@
## Preamble ## Preamble
EIP: <to be assigned> (I Suggest 20) EIP: 20
Title: <EIP title> Title: ERC-20 Token Standard
Author: Fabian Vogelsteller <fabian@ethereum.org>, Vitalik Buterin <vitalik.buterin@ethereum.org> Author: Fabian Vogelsteller <fabian@ethereum.org>, Vitalik Buterin <vitalik.buterin@ethereum.org>
Type: Informational Type: Standard
Status: Draft Category: ERC
Status: Accepted
Created: 2015-11-19 Created: 2015-11-19
@ -15,8 +16,8 @@ A standard interface for tokens.
## Abstract ## Abstract
The following standard allows for the implementation of a standard API for tokens within their smart contracts: The following standard allows for the implementation of a standard API for tokens within smart contracts.
it primarily provides basic functionality to transfer tokens and allow them to be approved to be spend by another on-chain third party. This standard provides basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party.
## Motivation ## Motivation
@ -29,91 +30,102 @@ A standard interface allows any tokens on Ethereum to be re-used by other applic
## Token ## Token
### Methods ### Methods
**NOTE**: An important point is that callers should handle `false` from `returns (bool success)`. Callers should not assume that `false` is never returned! **NOTE**: Callers should handle `false` from `returns (bool success)`. Callers should not assume that `false` is never returned!
#### name #### name
Returns the name of the token - e.g. `"MyToken"`
``` js ``` js
function name() constant returns (string name) function name() constant returns (string name)
``` ```
Returns the name of the token. E.g. "MyToken"
#### symbol #### symbol
Returns the symbol of the token. E.g. "MYT"
``` js ``` js
function symbol() constant returns (string symbol) function symbol() constant returns (string symbol)
``` ```
Returns the symbol of the token. E.g. "MYT"
#### decimals #### decimals
Returns the number of decimals the token uses - e.g. `8`, means to divide the token amount by `100000000` to get its user representation.
``` js ``` js
function decimals() constant returns (uint8 decimals) function decimals() constant returns (uint8 decimals)
``` ```
Returns the number of decimals the token uses. E.g. 8, which would mean to divide the token amount by 100000000 to get its user representation.
#### totalSupply #### totalSupply
Returns the total token supply.
``` js ``` js
function totalSupply() constant returns (uint256 totalSupply) function totalSupply() constant returns (uint256 totalSupply)
``` ```
Get the total token supply
#### balanceOf #### balanceOf
Returns the account balance of another account with address `_owner`.
``` js ``` js
function balanceOf(address _owner) constant returns (uint256 balance) function balanceOf(address _owner) constant returns (uint256 balance)
``` ```
Get the account balance of another account with address `_owner`
#### transfer #### transfer
Transfers `_value` amount of tokens to address `_to`.
The command should `throw` if the `_from` account balance has not enough tokens to spend.
``` js ``` js
function transfer(address _to, uint256 _value) returns (bool success) function transfer(address _to, uint256 _value) returns (bool success)
``` ```
Transfer `_value` amount of tokens to address `_to`
#### transferFrom #### transferFrom
Transfers `_value` amount of tokens from address `_from` to address `_to`.
The `transferFrom` method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf.
This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies.
The command should `throw` unless the `_from` account has deliberately authorized the sender of the message via some mechanism.
``` js ``` js
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) function transferFrom(address _from, address _to, uint256 _value) returns (bool success)
``` ```
Send `_value` amount of tokens from address `_from` to address `_to`
The `transferFrom` method is used for a withdraw workflow, allowing contracts to send tokens on your behalf, for example to "deposit" to a contract address and/or to charge fees in sub-currencies; the command should fail unless the `_from` account has deliberately authorized the sender of the message via some mechanism; we propose these standardized APIs for approval:
#### approve #### 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`.
**NOTE**: To prevent attack vectors like the one [described here](https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/) and discussed [here](https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729),
make sure to force users set the allowance to `0` before setting it to another value for the same spender.
``` js ``` js
function approve(address _spender, uint256 _value) returns (bool success) function approve(address _spender, uint256 _value) returns (bool success)
``` ```
Allow _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.
To prevent attack vectors like the one described here: https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
make sure to set the allowance to 0 before setting it to another value for the same spender.
#### allowance #### allowance
Returns the amount which `_spender` is still allowed to withdraw from `_owner`.
``` js ``` js
function allowance(address _owner, address _spender) constant returns (uint256 remaining) function allowance(address _owner, address _spender) constant returns (uint256 remaining)
``` ```
Returns the amount which `_spender` is still allowed to withdraw from `_owner`
### Events ### Events
@ -121,32 +133,34 @@ Returns the amount which `_spender` is still allowed to withdraw from `_owner`
#### Transfer #### Transfer
Triggered when tokens are transferred.
``` js ``` js
event Transfer(address indexed _from, address indexed _to, uint256 _value) event Transfer(address indexed _from, address indexed _to, uint256 _value)
``` ```
Triggered when tokens are transferred.
#### Approval #### Approval
Triggered when `approve(address _spender, uint256 _value)` is called.
``` js ``` js
event Approval(address indexed _owner, address indexed _spender, uint256 _value) event Approval(address indexed _owner, address indexed _spender, uint256 _value)
``` ```
Triggered whenever `approve(address _spender, uint256 _value)` is called.
## Implementation ## Implementation
There are already plenty of ERC20-compliant tokens deployed on the Ethereum network and is the most widely used standard. There are already plenty of ERC20-compliant tokens deployed on the Ethereum network.
Different implementations have been written by various teams that have different trade-offs: from gas saving to improved security. Different implementations have been written by various teams that have different trade-offs: from gas saving to improved security.
#### Example implementations are available at #### Example implementations are available at
- https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/StandardToken.sol - https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/StandardToken.sol
- https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/StandardToken.sol - https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/StandardToken.sol
#### Implementation adding the force 0 before calling approve again: #### Implementation of adding the force to 0 before calling "approve" again:
- https://github.com/Giveth/minime/blob/master/MiniMeToken.sol - https://github.com/Giveth/minime/blob/master/MiniMeToken.sol
## Copyright ## Copyright