2017-04-24 13:37:03 +00:00
## Preamble
2017-05-17 08:51:09 +00:00
EIP: 20
Title: ERC-20 Token Standard
2017-04-24 13:37:03 +00:00
Author: Fabian Vogelsteller < fabian @ ethereum . org > , Vitalik Buterin < vitalik.buterin @ ethereum . org >
2017-05-17 08:51:09 +00:00
Type: Standard
Category: ERC
Status: Accepted
2017-04-24 13:37:03 +00:00
Created: 2015-11-19
## Simple Summary
2017-05-03 13:38:54 +00:00
A standard interface for tokens.
2017-04-24 13:37:03 +00:00
## Abstract
2017-05-17 08:51:09 +00:00
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.
2017-04-24 13:37:03 +00:00
## Motivation
2017-05-03 13:38:54 +00:00
A standard interface allows any tokens on Ethereum to be re-used by other applications: from wallets to decentralized exchanges.
2017-04-24 13:37:03 +00:00
## Specification
## Token
### Methods
2017-05-17 08:51:09 +00:00
**NOTE**: Callers should handle `false` from `returns (bool success)` . Callers should not assume that `false` is never returned!
2017-04-24 13:37:03 +00:00
2017-05-03 13:45:15 +00:00
#### name
2017-05-17 08:51:09 +00:00
Returns the name of the token - e.g. `"MyToken"`
2017-05-03 13:45:15 +00:00
``` js
function name() constant returns (string name)
```
#### symbol
2017-05-17 08:51:09 +00:00
Returns the symbol of the token. E.g. "MYT"
2017-05-03 13:45:15 +00:00
``` js
function symbol() constant returns (string symbol)
```
#### decimals
2017-05-17 08:51:09 +00:00
Returns the number of decimals the token uses - e.g. `8` , means to divide the token amount by `100000000` to get its user representation.
2017-05-03 13:45:15 +00:00
``` js
function decimals() constant returns (uint8 decimals)
```
2017-04-24 13:37:03 +00:00
#### totalSupply
2017-05-17 08:51:09 +00:00
Returns the total token supply.
2017-04-24 13:37:03 +00:00
``` js
function totalSupply() constant returns (uint256 totalSupply)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### balanceOf
2017-05-17 08:51:09 +00:00
Returns the account balance of another account with address `_owner` .
2017-04-24 13:37:03 +00:00
``` js
function balanceOf(address _owner) constant returns (uint256 balance)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### transfer
2017-05-17 08:51:09 +00:00
Transfers `_value` amount of tokens to address `_to` .
The command should `throw` if the `_from` account balance has not enough tokens to spend.
2017-04-24 13:37:03 +00:00
``` js
function transfer(address _to, uint256 _value) returns (bool success)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### transferFrom
2017-05-17 08:51:09 +00:00
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.
2017-04-24 13:37:03 +00:00
``` js
function transferFrom(address _from, address _to, uint256 _value) returns (bool success)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### approve
2017-05-17 08:51:09 +00:00
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.
2017-04-24 13:37:03 +00:00
``` js
function approve(address _spender, uint256 _value) returns (bool success)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### allowance
2017-05-17 08:51:09 +00:00
Returns the amount which `_spender` is still allowed to withdraw from `_owner` .
2017-04-24 13:37:03 +00:00
``` js
function allowance(address _owner, address _spender) constant returns (uint256 remaining)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
### Events
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### Transfer
2017-05-17 08:51:09 +00:00
Triggered when tokens are transferred.
2017-04-24 13:37:03 +00:00
``` js
event Transfer(address indexed _from, address indexed _to, uint256 _value)
```
2017-04-24 13:42:04 +00:00
2017-04-24 13:37:03 +00:00
#### Approval
2017-05-17 08:51:09 +00:00
Triggered when `approve(address _spender, uint256 _value)` is called.
2017-04-24 13:37:03 +00:00
``` js
event Approval(address indexed _owner, address indexed _spender, uint256 _value)
```
## Implementation
2017-05-17 08:51:09 +00:00
There are already plenty of ERC20-compliant tokens deployed on the Ethereum network.
2017-05-03 13:38:54 +00:00
Different implementations have been written by various teams that have different trade-offs: from gas saving to improved security.
#### Example implementations are available at
2017-04-24 13:37:03 +00:00
- https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/StandardToken.sol
- https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/StandardToken.sol
2017-05-17 08:51:09 +00:00
#### Implementation of adding the force to 0 before calling "approve" again:
2017-06-12 10:34:00 +00:00
- https://github.com/Giveth/minime/blob/master/contracts/MiniMeToken.sol
2017-04-24 13:37:03 +00:00
## Copyright
Copyright and related rights waived via [CC0 ](https://creativecommons.org/publicdomain/zero/1.0/ ).