EIP: 995
Title: ERC995 Token Standard (ERC20 Extension)
Author: Prophet Daniel <[email protected]>
Type: Token Standard
Category: ERC
Created: 2018-04-12
Simple Summary
An extension of the standard interface ERC #20 for tokens with methods that allows the execution of calls inside transfer and approvals based on ERC #827.
Abstract
This standard provides an augmented token transfer functionality besides legacy proven ERC20 functionality. It allows to execute calls on transfers and approvals both before and after tokens are transferred regardless if the receiving address is a contract or not.
Motivation
This extension of the ERC20 interface allows any tokens on Ethereum to be re-used by other applications: from wallets to decentralized exchanges. The ERC20 token standard is widely accepted but it only allows the transfer of value, Ethereum users are available to transfer value and data on transactions, with this extension of the ERC20 token standard they will be able to do the same with ERC20 tokens.
There are a lot of new standards being proposed in the community. The natural evolution of ERC20 standard starts with compatibility with the original standard and also add new methods, but keeping it simple at the same time, the new functions proposed are still less than 100 lines of code taking in count the documentation.
When to use each function
-
approve: Probably the one that you will need, maybe the only one since it allows the receiver contract to use authenticated/approved balance. The best practice is to check the allowance of the sender and then do your stuff using the transferFrom method.
-
transfer: There is no way to check that the balance that will be transferred is the correct one, this function is useful when a function doesn't need to check any transfer of value.
-
transferFrom: Same as transfer, only useful when there is no need to check the transferred amount of tokens and caller wants to spend approved balance.
Specification
Token
Methods
NOTE: Callers MUST handle false from returns (bool success). Callers MUST NOT assume that false is never returned!
name - ERC20
Returns the name of the token - e.g. "MyToken".
OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
function name() constant returns (string name)
symbol - ERC20
Returns the symbol of the token. E.g. "HIX".
OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
function symbol() constant returns (string symbol)
decimals - ERC20
Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.
OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
function decimals() constant returns (uint8 decimals)
totalSupply - ERC20
Returns the total token supply.
function totalSupply() constant returns (uint256 totalSupply)
balanceOf - ERC20
Returns the account balance of another account with address _owner.
function balanceOf(address _owner) constant returns (uint256 balance)
transfer - ERC20
Transfers _value amount of tokens to address _to, and MUST fire the Transfer event.
The function SHOULD revert if the _from account balance does not have enough tokens to spend.
A token contract which creates new tokens SHOULD trigger a Transfer event with the _from address set to 0x0 when tokens are created.
Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
function transfer(address _to, uint256 _value) returns (bool success)
transferFrom - ERC20
Transfers _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.
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 function SHOULD revert unless the _from account has deliberately authorized the sender of the message via some mechanism.
Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
function transferFrom(address _from, address _to, uint256 _value) returns (bool success)
approve - ERC20
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.
Users SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender.
THOUGH The contract itself shouldn't enforce it, to allow backward compatibility with contracts deployed before
function approve(address _spender, uint256 _value) returns (bool success)
allowance - ERC20
Returns the amount which _spender is still allowed to withdraw from _owner.
function allowance(address _owner, address _spender) constant returns (uint256 remaining)
ERC995 methods
transfer - ERC995
Execute two functions on _dataContract with the _preData and _posData parameters respectively one before and one after the transfer. If both functions end successfully execute the transfer of _value amount of tokens to address _to and MUST fire the Transfer event.
The function SHOULD revert if any of the two calls to _dataContract address fails or if _from account balance does not have enough tokens to spend.
The ERC20 transfer method is called after _dataContract.call(_preData) and before the _dataContract.call(_posData).
Note: The _to address cant be the token address itself.
Note: Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
Important Note: Do not use this method with fallback functions that receive the value transferred as a parameter, there is no way to verify how much value was really transferred.
function transfer(
address _to,
address _dataContract,
uint256 _value,
bytes _preData,
bytes _posData
)
public onlyAnotherAddress(_to) returns (bool)
{
require(_dataContract.call(_preData));
super.transfer(_to, _value);
require(_dataContract.call(_posData));
return true;
}
transferFrom - ERC995
Execute two functions on _dataContract with the _preData and _posData parameters respectively one before and one after the transferFrom, If both functions end successfully execute the transfer of _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.
The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf after executing a function.
The ERC20 transferFrom method is called after _dataContract.call(_preData) and before the _dataContract.call(_posData).
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 function SHOULD revert if any of the two calls to _dataContract address fails or if the _from approved balance by _from to msg.sender is not enough to execute the transfer.
Note: The _to address cant be the token address itself.
Note: Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.
Important Note: Do not use this method with fallback functions that receive the value transferred as a parameter, there is no way to verify how much value was really transferred.
function transferFrom(
address _from,
address _to,
address _dataContract,
uint256 _value,
bytes _preData,
bytes _posData
)
public onlyAnotherAddress(_to) returns (bool)
{
require(_dataContract.call(_preData));
super.transferFrom(_from, _to, _value);
require(_dataContract.call(_posData));
return true;
}
approve - ERC995
Execute a function on _dataContract with the _preData and _posData parameters respectively one before and one after the approve, if both two calls to _dataContract address end successfully, _spender is allowed to withdraw from owner's account multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.
Clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender.
The ERC20 approve method is called after _dataContract.call(_preData) and before the _dataContract.call(_posData).
The function SHOULD revert if any of the two calls to _dataContract address fails.
THOUGH The contract itself shouldn't enforce it, to allow backward compatibility with contracts deployed before
Note: The _spender address cant be the token address itself.
function approve(
address _spender,
address _dataContract,
uint256 _value,
bytes _preData,
bytes _posData
)
public onlyAnotherAddress(_spender) returns (bool)
{
require(_dataContract.call(_preData));
super.approve(_spender, _value);
require(_dataContract.call(_posData));
return true;
}
Events
Transfer - ERC20
MUST trigger when tokens are transferred, including zero value transfers.
event Transfer(address indexed _from, address indexed _to, uint256 _value)
Approval - ERC20
MUST trigger on any successful call to approve(address _spender, uint256 _value).
event Approval(address indexed _owner, address indexed _spender, uint256 _value)
Revisions
2018/02/04: Initial Draft
Implementation
Copyright
Copy left, copy down, copy right: sonic boom
Simple Summary
An extension of the standard interface ERC #20 for tokens with methods that allows the execution of calls inside transfer and approvals based on ERC #827.
Abstract
This standard provides an augmented token transfer functionality besides legacy proven ERC20 functionality. It allows to execute calls on transfers and approvals both before and after tokens are transferred regardless if the receiving address is a contract or not.
Motivation
This extension of the ERC20 interface allows any tokens on Ethereum to be re-used by other applications: from wallets to decentralized exchanges. The ERC20 token standard is widely accepted but it only allows the transfer of value, Ethereum users are available to transfer value and data on transactions, with this extension of the ERC20 token standard they will be able to do the same with ERC20 tokens.
There are a lot of new standards being proposed in the community. The natural evolution of ERC20 standard starts with compatibility with the original standard and also add new methods, but keeping it simple at the same time, the new functions proposed are still less than 100 lines of code taking in count the documentation.
When to use each function
approve: Probably the one that you will need, maybe the only one since it allows the receiver contract to use authenticated/approved balance. The best practice is to check the allowance of the sender and then do your stuff using the
transferFrommethod.transfer: There is no way to check that the balance that will be transferred is the correct one, this function is useful when a function doesn't need to check any transfer of value.transferFrom: Same astransfer, only useful when there is no need to check the transferred amount of tokens and caller wants to spend approved balance.Specification
Token
Methods
NOTE: Callers MUST handle
falsefromreturns (bool success). Callers MUST NOT assume thatfalseis never returned!name - ERC20
Returns the name of the token - e.g.
"MyToken".OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
symbol - ERC20
Returns the symbol of the token. E.g.
"HIX".OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
decimals - ERC20
Returns the number of decimals the token uses - e.g.
8, means to divide the token amount by100000000to get its user representation.OPTIONAL - This method can be used to improve usability,
but interfaces and other contracts MUST NOT expect these values to be present.
totalSupply - ERC20
Returns the total token supply.
balanceOf - ERC20
Returns the account balance of another account with address
_owner.transfer - ERC20
Transfers
_valueamount of tokens to address_to, and MUST fire theTransferevent.The function SHOULD
revertif the_fromaccount balance does not have enough tokens to spend.A token contract which creates new tokens SHOULD trigger a Transfer event with the
_fromaddress set to0x0when tokens are created.Note Transfers of 0 values MUST be treated as normal transfers and fire the
Transferevent.transferFrom - ERC20
Transfers
_valueamount of tokens from address_fromto address_to, and MUST fire theTransferevent.The
transferFrommethod 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 function SHOULD
revertunless the_fromaccount has deliberately authorized the sender of the message via some mechanism.Note Transfers of 0 values MUST be treated as normal transfers and fire the
Transferevent.approve - ERC20
Allows
_spenderto withdraw from your account multiple times, up to the_valueamount. If this function is called again it overwrites the current allowance with_value.Users SHOULD make sure to create user interfaces in such a way that they set the allowance first to
0before setting it to another value for the same spender.THOUGH The contract itself shouldn't enforce it, to allow backward compatibility with contracts deployed before
allowance - ERC20
Returns the amount which
_spenderis still allowed to withdraw from_owner.ERC995 methods
transfer - ERC995
Execute two functions on
_dataContractwith the_preDataand_posDataparameters respectively one before and one after thetransfer. If both functions end successfully execute the transfer of_valueamount of tokens to address_toand MUST fire theTransferevent.The function SHOULD
revertif any of the two calls to_dataContractaddress fails or if_fromaccount balance does not have enough tokens to spend.The ERC20
transfermethod is called after_dataContract.call(_preData)and before the_dataContract.call(_posData).Note: The
_toaddress cant be the token address itself.Note: Transfers of
0values MUST be treated as normal transfers and fire theTransferevent.Important Note: Do not use this method with fallback functions that receive the value transferred as a parameter, there is no way to verify how much value was really transferred.
transferFrom - ERC995
Execute two functions on
_dataContractwith the_preDataand_posDataparameters respectively one before and one after thetransferFrom, If both functions end successfully execute the transfer of_valueamount of tokens from address_fromto address_to, and MUST fire theTransferevent.The
transferFrommethod is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf after executing a function.The ERC20
transferFrommethod is called after_dataContract.call(_preData)and before the_dataContract.call(_posData).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 function SHOULD
revertif any of the two calls to_dataContractaddress fails or if the_fromapproved balance by_fromtomsg.senderis not enough to execute the transfer.Note: The
_toaddress cant be the token address itself.Note: Transfers of
0values MUST be treated as normal transfers and fire theTransferevent.Important Note: Do not use this method with fallback functions that receive the value transferred as a parameter, there is no way to verify how much value was really transferred.
approve - ERC995
Execute a function on
_dataContractwith the_preDataand_posDataparameters respectively one before and one after theapprove, if both two calls to_dataContractaddress end successfully,_spenderis allowed to withdraw from owner's account multiple times, up to the_valueamount. If this function is called again it overwrites the current allowance with_value.Clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to
0before setting it to another value for the same spender.The ERC20
approvemethod is called after_dataContract.call(_preData)and before the_dataContract.call(_posData).The function SHOULD
revertif any of the two calls to_dataContractaddress fails.THOUGH The contract itself shouldn't enforce it, to allow backward compatibility with contracts deployed before
Note: The
_spenderaddress cant be the token address itself.Events
Transfer - ERC20
MUST trigger when tokens are transferred, including zero value transfers.
Approval - ERC20
MUST trigger on any successful call to
approve(address _spender, uint256 _value).Revisions
2018/02/04: Initial Draft
Implementation
Copyright
Copy left, copy down, copy right: sonic boom