EIP-223 on Ethereum project: https://github.com/ethereum/EIPs/issues/223
The following describes standard functions a token contract and contract working with specified token can implement to prevent accidentally sends of tokens to contracts and make token transactions behave like ether transactions.
Two problems of ERC20 that ERC23 will solve:
- When you are sending tokens receiver will never know that transaction appears. Addresses don’t care about it while contracts my need to handle transactions.
- Tokens could be sent to another contract address where would not be accessible anymore.
Those will allow dapps and wallets to handle incoming token transactions and prevent accidentally sent tokens from being accepted by contracts.
For example decentralized exchange will no more need to force users to call
approve at token contract then call
deposit that is calling
transferFrom taking allowed tokens. Token transaction will automatically be handled inside the exchange contract.
The most important here are,
Token Contracts that work with tokens
NOTE: An important point is that contract developers should handle
fallbackToken like fallback for ether transactions if they wish their contracts to work with specified tokens.
Token contract methods
function isContract(address _addr) private returns (bool is_contract)
private function that assembles
extcodesize(_addr) and returns
true if code size is greater than 0. It’s needed to choose which function to use
transferToContract depending on is the reveiver a contract or not.
function transferToContract(address _to, uint _value) private returns (bool success)
private function that transfers tokens from
_to then trying to call
fallbackToken(msg.sender, _value) at
function transferToAddress(address _to, uint _value) private returns (bool success)
private function similar to base ERC20
function transfer(address _to, uint _value) returns (bool success)
function that is always called when someone wants to transfer tokens. Calls
transferToContract depending on is the reveiver an address or a contract.
Contract to work with tokens
mapping (address => bool) supportedTokens;
Mapping of addresses of token contracts that are supported.
function addToken(address _token)
Allows a token contract address to work with.
function removeToken(address _token)
Makes a given token contract address no more allowed to work with.
function fallbackToken(address _from, uint _value)
A function to handle token transfers that is called from token contract when token holder is sending tokens.
_from is a token holder and
_value is amount of incoming tokens. Works like fallback function for Ether transactions.