| iip | 2 |
|---|---|
| title | ICON Token Standard |
| author | Jaechang Namgoong (@sink772) |
| discussions-to | #2 |
| status | Final |
| type | Standards Track |
| category | IRC |
| created | 2018-08-07 |
A standard interface for tokens on ICON network.
This draft IRC describes a token standard interface to provide basic functionality to transfer tokens. We adopted the token fallback mechanism inspired by ERC223, that a token contract can implement to prevent accidental transfers of tokens to contracts and make token transactions behave like other ICX transactions.
A token standard interface allows any tokens on ICON to be re-used by other third parties, from wallets to decentralized exchanges.
Returns the name of the token. e.g. MySampleToken.
@external(readonly=True)
def name(self) -> str:Returns the symbol of the token. e.g. MST.
@external(readonly=True)
def symbol(self) -> str:Returns the number of decimals the token uses. e.g. 18.
@external(readonly=True)
def decimals(self) -> int:Returns the total token supply.
@external(readonly=True)
def totalSupply(self) -> int:Returns the account balance of another account with address _owner.
@external(readonly=True)
def balanceOf(self, _owner: Address) -> int:Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. This function SHOULD throw if the self.msg.sender account balance does not have enough tokens to spend. If _to is a contract, this function MUST invoke the function tokenFallback(Address, int, bytes) in _to. If the tokenFallback function is not implemented in _to (receiver contract), then the transaction must fail and the transfer of tokens should not occur. If _to is an externally owned address, then the transaction must be sent without trying to execute tokenFallback in _to. _data can be attached to this token transaction. _data can be empty.
@external
def transfer(self, _to: Address, _value: int, _data: bytes=None):Must trigger on any successful token transfers.
@eventlog(indexed=3)
def Transfer(self, _from: Address, _to: Address, _value: int, _data: bytes):
passA function for handling token transfers, which is called from the token contract, when a token holder sends tokens. _from is the address of the sender of the token, _value is the amount of incoming tokens, and _data is arbitrary attached data. It works by analogy with the fallback function of the normal transactions and returns nothing.
@external
def tokenFallback(self, _from: Address, _value: int, _data: bytes):https://github.com/icon-project/samples/tree/master/irc2_token- A Java SCORE Library for ICON Standard Tokens
Copyright and related rights waived via CC0.