Skip to content

Latest commit

 

History

History
146 lines (97 loc) · 4.67 KB

OEP-4.mediawiki

File metadata and controls

146 lines (97 loc) · 4.67 KB

  OEP: 4
  Title: Token Standard
  Author: luodanwg <[email protected]>, tanyuan <[email protected]>, zhoupw <[email protected]>
  Type: Standard
  Status: Accepted
  Created: 2018-07-03

Table of Contents

Abstract

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.

Motivation

A standard token interface which allows tokens on the Ontology blockchain to be conveniently used by other applications.

Specification

Methods

name

def name()

Returns a string, the name of the token - e.g. "MyToken".

symbol

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).

decimals

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.

totalSupply

def totalSupply()

Returns the total number of tokens.

balanceOf

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.

transfer

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.

transferMulti

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 amounts 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.

approve

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.

transferFrom

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.

allowance

def allowance(owner, spender)

Returns the amount which the spender address is still allowed to withdraw from the owner address.

Events

transfer

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.

approval

ApprovalEvent = RegisterAction("approval", "owner", "spender", "amount")

The event must be triggered on any successful calls to approve.

Implementation

TowerBuilders OEP-4 Example: Python Template

ONT-Avocados OEP-4 Example: Python Template