BEPs protocol: BUMO ATP 20 protocol

Keywords: JSON Attribute Javascript

BUMO ATP 20 Protocol

brief introduction

ATP 20(Account based Tokenization Protocol) refers to the standard protocol for issuing tokens based on BUMO smart contracts.The protocol provides the basic functionality to transfer tokens and allows tokens to be authorized for use by third parties.

target

Based on this standard set of interfaces, token s can be quickly docked and used by other applications and third parties, such as wallets and exchanges.

rule

The BUMO smart contract is implemented by the JavaScript language and contains the init initialization function and two entry functions, main and query.The init function is used to initialize contract creation; the main function is mainly responsible for data writing, and the query function is responsible for data query.

Token attribute

The Token attribute can be queried through the tokenInfo function of the contract and stored in the account of the smart contract.Contains the following

variable describe
name Token Name
symbol Token Symbol
decimals Token decimal places
totalSupply Total Token
version ATP Version

Be careful:

  • name: It is recommended to spell the whole word in uppercase letters.For example, Demo Token
  • symbol: Capital initials are recommended.Such as DT
  • Decimals: decimals are in the range of 0-8, 0 means no decimals.
  • TotSupply: Range is (1~2 ^ 63 - 1).If you issue an ATP 20 Token with a quantity of 10,000 and an accuracy of 8, then total Supply = 10 ^ 8 * 10,000, the result is 1000,000,000.
  • Version: The version of atp.Such as ATP20

Event

function transfer,transferFrom,approve Events are triggered (see the function descriptions for details), which call the tlog interface and record a transaction log on the block chain, which records the function call details for easy user reading.

The tlog is defined as follows:

tlog(topic,args...);
  • tlog produces a transaction written on the block
  • Topic: Log topic, must be of string type, parameter length (0,128)
  • args...: A maximum of five parameters can be of type string, numeric, or Boolean, with each parameter length (0,1024)

Functional Functions

Functions in the BUMO ATP 20 protocol include transfer,transferFrom,approve,balanceOf,tokenInfo,allowance.

transfer

  • function

    Transfer the number of tokens for the value to the destination address to, and the log event must be triggered.The function should be throw n if the funds transfer account balance does not have enough tokens to expend.

  • Entry function

    main

  • Parameter json structure

    {
        "method":"transfer",
        "params":{
            "to":"buQnTmK9iBFHyG2oLce7vcejPQ1g5xLVycsj",
            "value":"1000000"
        }
    }
    
  • json parameter

    parameter describe
    to Target Account Address
    value Number of transfers (string type)
  • function

    function transfer(to, value)
    
  • Return value

    true or throw an exception

  • Event

    tlog('transfer', sender, to, value);
    

    topic: method name, transfer here

    sender:Contract Call Account Address

    to:Destination Account Address

    value: Number of transfers (string type)

approve

  • function

    The authorized account spender can transfer a token of value from the transaction sender account.

  • Entry function

    main

  • Parameter json structure

    {
        "method":"approve",
        "params":{
            "spender":"buQnTmK9iBFHyG2oLce7vcejPQ1g5xLVycsj",
            "value":"1000000"
        }
    }
    
  • json parameter

    parameter describe
    spender Account Address
    value Authorized Transferable Quantity (String Type)
  • function

    function approve(spender, value)
    
  • Return value

    true or throw an exception

  • Event

    tlog('approve', sender, spender, value);
    

    topic: Method name, here is'approve'

    sender:Contract Call Account Address

    spender:Authorized account address

    value: Authorized Transferable Quantity (String Type)

transferFrom

  • function

    The log event must be triggered when a token of value is sent from the front to the to.Before transferFrom, From must grant an authorization limit to the initiator of the current transaction (that is, the approve operation).The function should be throw n if the from balance does not have enough tokens to spend or if the from authorizes insufficient amounts to the initiator of the current transaction.

  • Entry function

    main

  • Parameter json structure

    {
        "method":"transferFrom",
        "params":{
            "from":"buQnTmK9iBFHyG2oLce7vcejPQ1g5xLVycsj",
            "to":"buQYH2VeL87svMuj2TdhgmoH9wSmcqrfBner",
            "value":"1000000"
        }
    }
    
  • json parameter

    parameter describe
    from Source Account Address
    to Target Account Address
    value Number of transfers (string type)
  • function

    function transferFrom(from,to,value)
    
  • Return value

    true or throw an exception

  • Event

    tlog('transferFrom', sender, from, to, value);
    

    topic: method name, here'transferFrom'

    sender:Contract Call Account Address

    from:Source Account Address

    to:Destination Account Address

    value: Number of transfers (string type)

balanceOf

  • function

    Returns the token of the specified account.

  • Entry function

    query

  • Parameter json structure

    {
        "method":"balanceOf",
        "params":{
            "address":"buQnTmK9iBFHyG2oLce7vcejPQ1g5xLVycsj"
        }
    }
    
  • json parameter

    parameter describe
    address Account Address
  • function

    function balanceOf(owner)
    
  • Return value: Balance at specified address

    {
        "result":{
            "balanceOf":"100000000000000",
        }
    } 
    

tokenInfo

  • function

    Returns basic information about Token.

  • Entry function

    query

  • Parameter json structure

    {
        "method":"tokenInfo"
    }
    
  • function

    function tokenInfo()
    
  • Return value

    {
        "result":{
            "type": "string",
            "value": {
                "tokenInfo": {
                    "name": "DemoToken",
                    "symbol": "DT",
                    "decimals": 8,
                    "totalSupply": "5000000000000",
                    "version": "1.0"
                }
            }
        }
    } 
    

allowance

  • function

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

  • Entry function

    query

  • Parameter json structure

    {
        "method":"allowance",
        "params":{
            "owner":"buQnTmK9iBFHyG2oLce7vcejPQ1g5xLVycsj",
            "spender":"buQYH2VeL87svMuj2TdhgmoH9wSmcqrfBner"
        }
    }
    
  • json parameter

    parameter describe
    owner Account Address
    spender Account Address
  • function

    function allowance(owner, spender)
    
  • Return value

    {
        "result":{
            "allowance":"1000000",
        }
    } 
    

Contract Entry

init

  • When creating a contract, triggers the contract init entry function, which is responsible for the initialization of the contract when it is created.

  • function

    function init(input_str){
    }
    
  • Parameter Json structure

    {
        "params":{
            "name":"DemoToken",
            "symbol":"DT",
            "decimals":8,
            "totalSupply":"5000000000000",
            "version": "1.0"
        }
    }
    
  • Return value

    true or throw an exception

main

  • Responsible for data writing, which contains transfer,transferFrom,approve.

  • Function Body

    function main(input_str){
        let input = JSON.parse(input_str);
    
        if(input.method === 'transfer'){
            transfer(input.params.to, input.params.value);
        }
        else if(input.method === 'transferFrom'){
            transferFrom(input.params.from, input.params.to, input.params.value);
        }
        else if(input.method === 'approve'){
            approve(input.params.spender, input.params.value);
        }
        else{
            throw '<Main interface passes an invalid operation type>';
        }
    }
    

query

  • Responsible for data queries, which include tokenInfo,allowance And so on.

  • Function Body

    function query(input_str){
        globalAttribute = JSON.parse(storageLoad(globalAttributeKey));
    
        let result = {};
        let input  = JSON.parse(input_str);
    
        if(input.method === 'tokenInfo'){
            result.tokenInfo = globalAttribute;
        }
        else if(input.method === 'allowance'){
            result.allowance = allowance(input.params.owner, input.params.spender);
        }
        else{
            throw '<Query interface passes an invalid operation type>';
        }
        return JSON.stringify(result);
    }

Posted by bonekrusher on Sun, 05 May 2019 01:56:37 -0700