Skip to content

Latest commit

 

History

History
189 lines (146 loc) · 5.58 KB

nep-17.mediawiki

File metadata and controls

189 lines (146 loc) · 5.58 KB

  NEP: 17
  Title: Token Standard
  Author: Erik Zhang <[email protected]>
  Type: Standard
  Status: Final
  Created: 2020-11-12
  Replaces: 5

Table of Contents

Abstract

This proposal outlines a token standard for the NEO blockchain that will provide systems with a generalized interaction mechanism for tokenized Smart Contracts. This mechanic, along with the justification for each feature are defined. A template and examples are also provided to enable the development community.

Motivation

As the NEO blockchain scales, Smart Contract deployment and invocation will become increasingly important. Without a standard interaction method, systems will be required to maintain a unique API for each contract, regardless of their similarity to other contracts. Tokenized contracts present themselves as a prime example of this need because their basic operating mechanism is the same. A standard method for interacting with these tokens relieves the entire ecosystem from maintaining a definition for basic operations that are required by every Smart Contract that employs a token.

Specification

In the method definitions below, we provide both the definitions of the functions as they are defined in the contract as well as the invoke parameters.

Methods

symbol

{
  "name": "symbol",
  "safe": true,
  "parameters": [],
  "returntype": "String"
}

Returns a short string representing symbol of the token managed in this contract. e.g. "MYT". This string MUST be valid ASCII, MUST NOT contain whitespace or control characters, SHOULD be limited to uppercase Latin alphabet (i.e. the 26 letters used in English) and SHOULD be short (3-8 characters is recommended).

This method MUST always return the same value every time it is invoked.

decimals

{
  "name": "decimals",
  "safe": true,
  "parameters": [],
  "returntype": "Integer"
}

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.

This method MUST always return the same value every time it is invoked.

totalSupply

{
  "name": "totalSupply",
  "safe": true,
  "parameters": [],
  "returntype": "Integer"
}

Returns the total token supply deployed in the system.

balanceOf

{
  "name": "balanceOf",
  "safe": true,
  "parameters": [
    {
      "name": "account",
      "type": "Hash160"
    }
  ],
  "returntype": "Integer"
}

Returns the token balance of the account.

The parameter account MUST be a 20-byte address. If not, this method SHOULD throw an exception.

If the account is an unused address, this method MUST return 0.

transfer

{
  "name": "transfer",
  "safe": false,
  "parameters": [
    {
      "name": "from",
      "type": "Hash160"
    },
    {
      "name": "to",
      "type": "Hash160"
    },
    {
      "name": "amount",
      "type": "Integer"
    },
    {
      "name": "data",
      "type": "Any"
    }
  ],
  "returntype": "Boolean"
}

Transfers an amount of tokens from the from account to the to account.

The parameters from and to MUST be 20-byte addresses. If not, this method SHOULD throw an exception.

The parameter amount MUST be greater than or equal to 0. If not, this method SHOULD throw an exception.

The function MUST return false if the from account balance does not have enough tokens to spend.

If the method succeeds, it MUST fire the Transfer event, and MUST return true, even if the amount is 0, or from and to are the same address.

The function SHOULD check whether the from address equals the caller contract hash. If so, the transfer SHOULD be processed; If not, the function SHOULD use the SYSCALL Neo.Runtime.CheckWitness to verify the transfer.

If the transfer is not processed, the function MUST return false.

If the receiver is a deployed contract, the function MUST call onNEP17Payment method on receiver contract with the data parameter from transfer AFTER firing the Transfer event. If the receiver doesn't want to receive this transfer it MUST call ABORT.

{
  "name": "onNEP17Payment",
  "parameters": [
    {
      "name": "from",
      "type": "Hash160"
    },
    {
      "name": "amount",
      "type": "Integer"
    },
    {
      "name": "data",
      "type": "Any"
    }
  ],
  "returntype": "Void"
}

Events

Transfer

{
  "name": "Transfer",
  "parameters": [
    {
      "name": "from",
      "type": "Hash160"
    },
    {
      "name": "to",
      "type": "Hash160"
    },
    {
      "name": "amount",
      "type": "Integer"
    }
  ]
}

MUST trigger when tokens are transferred, including zero value transfers and self-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.

Implementation

C#: https://github.com/neo-project/neo-devpack-dotnet/blob/master/src/Neo.SmartContract.Framework/Nep17Token.cs

Python: https://github.com/CityOfZion/neo3-boa/blob/development/boa3_test/examples/nep17.py