OEP: 4 Title: Token Standard Author: luodanwg <luodan.wg@gmail.com>, tanyuan <tanyuan666@gmail.com>, zhoupw <zhoupw@gmail.com> Type: Standard Status: Accepted Created: 2018-07-03
The OEP-4 Proposal is a standard interface for tokens. This standard allows for the implementation of a standard API for tokens within smart contracts.
A standard token interface which allows tokens on the Ontology blockchain to be conveniently used by other applications.
def name()
Returns a string
, the name of the token - e.g. "MyToken".
def symbol()
Returns a string
, the short symbol of the token - e.g. "MYT"
.
This symbol should be short (3-8 characters is recommended), with no whitespace characters or new-lines and should be limited to the uppercase latin alphabet (i.e. the 26 letters used in English).
def decimals()
Returns the number of decimals used by the token - e.g. 8
, means to divide the token amount by 100,000,000
to get its user representation.
def totalSupply()
Returns the total number of tokens.
def balanceOf(address)
Returns the token balance of the address
.
The parameter address
must be a 20-byte address. If not, this method must throw
an exception.
def transfer(from, to, amount)
Transfers an amount
of tokens from the from
account to the to
account.
The parameters from
and to
must be 20-byte address. If not, this method must throw
an exception.
The parameter amount
is the number of tokens to transfer, must be greater than or equal to 0.
def TransferMulti(args) state = { from: <FROM ADDRESS>, to: <TO ADDRESS>, amount: <AMOUNT> }
The transferMulti function allows the transferring of tokens from multiple from
addresses to multiple to
addresses with multiple amount
s of tokens.
The parameter is an array of objects, the object is a state
struct, which contains three items: the sender address from
(which must be 20-byte address), the receiver address to
(which must be 20-byte address) and the amount
of tokens to transfer.
If any of the transfers fail, all of the transfers must be failed, and the method must throw
an exception.
def approve(owner, spender, amount)
The approve function allows the spender
address to withdraw tokens from the owner
address, of up to amount
tokens.
If this function is called again it overwrites the current allowance with the new value.
The parameters owner
and spender
must be 20-byte addresses.
If not, this method must throw
an exception.
def transferFrom(spender, from, to, amount)
The transferFrom method is used for a withdraw workflow - allowing the spender
address to withdraw amount
tokens from the from
address and send it to the to
address.
The parameters spender
, from
and to
must all be 20-byte addresses.
If not, this method must throw
an exception.
def allowance(owner, spender)
Returns the amount which the spender
address is still allowed to withdraw from the owner
address.
TransferEvent = RegisterAction("transfer", "from", "to", "amount")
The event must be triggered when tokens are transferred, including zero value transfers.
A token contract which creates new tokens must trigger a transfer
event with the from
address set to null
when tokens are created.
A token contract which burns tokens must trigger a transfer
event with the to
address set to null
when tokens are burned.
ApprovalEvent = RegisterAction("approval", "owner", "spender", "amount")
The event must be triggered on any successful calls to approve.
TowerBuilders OEP-4 Example: Python Template
ONT-Avocados OEP-4 Example: Python Template