-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERC20 Token Standard #610
ERC20 Token Standard #610
Changes from 6 commits
80fa7db
4f98798
d540a40
c96876e
2af51d6
b5902d3
a447ded
ed1c87a
efa1fc7
dd7e548
94bc431
e0cc8c2
3a45fb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
## Preamble | ||
|
||
EIP: 20 | ||
Title: ERC-20 Token Standard | ||
Author: Fabian Vogelsteller <fabian@ethereum.org>, Vitalik Buterin <vitalik.buterin@ethereum.org> | ||
Type: Standard | ||
Category: ERC | ||
Status: Accepted | ||
Created: 2015-11-19 | ||
|
||
|
||
## Simple Summary | ||
|
||
A standard interface for tokens. | ||
|
||
|
||
## Abstract | ||
|
||
The following standard allows for the implementation of a standard API for tokens within smart contracts. | ||
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 | ||
|
||
A standard interface allows any tokens on Ethereum to be re-used by other applications: from wallets to decentralized exchanges. | ||
|
||
|
||
## Specification | ||
|
||
## Token | ||
### Methods | ||
|
||
**NOTE**: Callers should handle `false` from `returns (bool success)`. Callers should not assume that `false` is never returned! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll be making suggestions to make the document clearer per RFC 2119. should handle |
||
|
||
#### name | ||
|
||
Returns the name of the token - e.g. `"MyToken"` | ||
|
||
``` js | ||
function name() constant returns (string name) | ||
``` | ||
|
||
|
||
#### symbol | ||
|
||
Returns the symbol of the token. E.g. "MYT" | ||
|
||
``` js | ||
function symbol() constant returns (string symbol) | ||
``` | ||
|
||
|
||
|
||
#### 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 | ||
function decimals() constant returns (uint8 decimals) | ||
``` | ||
|
||
|
||
#### totalSupply | ||
|
||
Returns the total token supply. | ||
|
||
``` js | ||
function totalSupply() constant returns (uint256 totalSupply) | ||
``` | ||
|
||
|
||
|
||
#### balanceOf | ||
|
||
Returns the account balance of another account with address `_owner`. | ||
|
||
``` js | ||
function balanceOf(address _owner) constant returns (uint256 balance) | ||
``` | ||
|
||
|
||
|
||
#### transfer | ||
|
||
Transfers `_value` amount of tokens to address `_to`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add:
For some discussion see Consensys/Tokens#47 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that transferring zero tokens should usually be treated as success and though should return true, but I'm not sure about event. According to current specification, "Transfer" event "triggered when tokens are transferred", and one may interpret this as "when tokens change hands". There are no references to "transfer", "transferFrom" or some other method in event specifications. So, when "transfer" or "transferFrom" method was called, but no tokens actually changed hands (i.e. zero tokens were transferred or "from" and "to" addresses are the same), no event should probably be logged. On the other hand, if tokens changed hands for some reason other than execution of "transfer" or "transferFrom" method, the event should be logged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes definitely: we can make this clearer when we can get some clarity on #610 (comment) |
||
The command should `throw` if the `_from` account balance has not enough tokens to spend. | ||
|
||
|
||
``` js | ||
function transfer(address _to, uint256 _value) returns (bool success) | ||
``` | ||
|
||
|
||
|
||
#### transferFrom | ||
|
||
Transfers `_value` amount of tokens from address `_from` to address `_to`. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that when amount == 0 it should return true, but no Transfer event should be emmited because there is no transfer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid point that 0 tokens are transferred, but most current implementations fire the event when |
||
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 | ||
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) | ||
``` | ||
|
||
|
||
|
||
#### 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: "force users set" -> "force users to set" |
||
|
||
``` js | ||
function approve(address _spender, uint256 _value) returns (bool success) | ||
``` | ||
|
||
|
||
#### allowance | ||
|
||
Returns the amount which `_spender` is still allowed to withdraw from `_owner`. | ||
|
||
``` js | ||
function allowance(address _owner, address _spender) constant returns (uint256 remaining) | ||
``` | ||
|
||
|
||
|
||
### Events | ||
|
||
|
||
#### Transfer | ||
|
||
Triggered when tokens are transferred. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MUST trigger whenever tokens move. If tokens are created, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "If tokens are created, _from of 0 MAY be used." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @frozeman Is this clearer: "If tokens are created, a Here is an example: https://github.com/ConsenSys/gnosis-contracts/blob/master/contracts/solidity/Tokens/GnosisToken.sol#L38 |
||
|
||
``` js | ||
event Transfer(address indexed _from, address indexed _to, uint256 _value) | ||
``` | ||
|
||
|
||
|
||
#### Approval | ||
|
||
Triggered when `approve(address _spender, uint256 _value)` is called. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Triggered when" -> MUST trigger when |
||
|
||
``` js | ||
event Approval(address indexed _owner, address indexed _spender, uint256 _value) | ||
``` | ||
|
||
|
||
|
||
## Implementation | ||
|
||
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. | ||
|
||
#### Example implementations are available at | ||
- https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/StandardToken.sol | ||
- https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/StandardToken.sol | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/Giveth/minime/blob/master/contracts/MiniMeToken.sol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :-D!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also like to see the MiniMeToken added to this list. Maintaining historical balance data is key for a number of token use cases. |
||
#### Implementation of adding the force to 0 before calling "approve" again: | ||
- https://github.com/Giveth/minime/blob/master/contracts/MiniMeToken.sol | ||
|
||
## Copyright | ||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding: