ECIP 1021: Token standard Source

AuthorDexaran,
StatusDraft
TypeStandards Track
CategoryECBP
Created2017-03-07
Resolutionhttps://github.com/Dexaran/ERC23-tokens

EIP-223 on Ethereum project: https://github.com/ethereum/EIPs/issues/223

Abstract

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.

Motivation

Two problems of ERC20 that ERC23 will solve:

  1. 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.
  2. 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, transferToContract and fallbackToken.

Specification

Token Contracts that work with tokens

Methods

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

isContract

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 transferToAddress or transferToContract depending on is the reveiver a contract or not.

transferToContract

function transferToContract(address _to, uint _value) private returns (bool success) private function that transfers tokens from msg.sender to _to then trying to call fallbackToken(msg.sender, _value) at _to.

transferToAddress

function transferToAddress(address _to, uint _value) private returns (bool success) private function similar to base ERC20 transfer

transfer

function transfer(address _to, uint _value) returns (bool success) function that is always called when someone wants to transfer tokens. Calls transferToAddress or transferToContract depending on is the reveiver an address or a contract.

Contract to work with tokens

supportedTokens

mapping (address => bool) supportedTokens; Mapping of addresses of token contracts that are supported.

addToken

function addToken(address _token) Allows a token contract address to work with.

removeToken

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.