9.3 DApp Development Interface

  • Get the account name

    window.BcxWeb.account_name

Get the transfer fee

Interface name

transferAsset

Request parameter

Parameter
Type
Must or Not
Description

fromAccount

Sting

M

Sender

toAccount

Sting

M

Receiver

amount

Sting

M

Amount

assetId

Sting

M

Assets ID(Eg. XXX) or Token Symbol(Eg. COCOS)

memo

Sting

N

Memo

feeAssetId

Sting

M

Token asset symbol for fee payment

isPropose

boolean

M

Propose or not

onlyGetFee

boolean

M

true:Only get operation fee;
false:Make a transfer

Example for data format response:

Data return for only get the transfer fee(onlyGetFee = true):

{
    "code":1,
    "data":{
        "fee_amount":2.08984,
        "fee_symbol":"COCOS"
    }
}

Data return for making a transfer(onlyGetFee = false)(Mobile terminal only offered trx_id field):

{
    "code":1,
    "data":[
        {
            "real_running_time":179
        }
    ],
    "trx_data":{
        "trx_id":"bfa20c68506dd830fe3217427835d5c186badc04839eab7ad2e923773fd8671d",
        "block_num":5226795
    }
}

Insufficient balance:

{
    "code":0,
    "message":"Assert Exception: from != to: ",
    "error":{
        "code":56,
        "message":"Assert Exception: from != to: ",
        "messageDetail":"Assert Exception: from != to: 
digest ec9e01d053bb55a3bd21c548f8ff4c27e7a077152ddd1b1ab65fa88b4d518fe4 transaction 660b90f837c620cbbf5c0100400d030000000000008801880140420f000000000000000000 {"ref_block_num":2918,"ref_block_prefix":3325556880,"expiration":"2019-04-24T02:34:08","operations":[[0,{"fee":{"amount":"200000","asset_id":"1.3.0"},"from":"1.2.136","to":"1.2.136","amount":{"amount":"1000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2002777d6199243d4dca821512fec827948ee840aca03cd14480e75b581c7456ad5e2a5a926320a9280d78631663659beffafb144629aa8ee3d8cb51d312eef81d"]}"
    }
}

Not logged in:

{
    "code":-11,
    "message":"Please login first"
}

Memo encryption failed:

{
    "code":118,
    "message":"Encrypt memo failed",
    "error":{
        "message":"Encrypt memo failed"
    }
}

Call contract function

Interface name

callContractFunction

Request parameter

Parameter
Type
Must or Not
Description

nameOrId

Sting

M

Contract name or ID

functionName

Sting

M

Target function name

valueList(array)

array

M

Parameter list

runtime

ong

N

runTime(in ms)

onlyGetFee

boolean

M

true:Only get operation fee;
false:Make a transfer

Example for data format response:
Data return for only get operation fee for this time(onlyGetFee = true):

{
    "code":1,
    "data":{
        "fee_amount":2.08984,
        "fee_symbol":"COCOS"
    }
}

Data return for this operation(onlyGetFee = false)(Mobile terminal only offered trx_id field):

{
    "code":1,
    "data":[
        {
            "real_running_time":179
        }
    ],
    "trx_data":{
        "trx_id":"bfa20c68506dd830fe3217427835d5c186badc04839eab7ad2e923773fd8671d",
        "block_num":5226795
    }
}

Signature failed:

{
    "code":0,
    "message":"Transaction was not signed. Do you have a private key? [no_signers]",
    "error":{
        "message":"Transaction was not signed. Do you have a private key? [no_signers]"
    }
}

Insufficient balance:

{
    "code":0,
    "message":"Assert Exception: itr->get_balance() >= -delta: Insufficient Balance: gnkhandsome1's balance of 2.12396 COCOS is less than required 2.72090 COCOS",
    "error":{
        "code":24,
        "message":"Assert Exception: itr->get_balance() >= 2.12396 COCOS is less than required 2.72090 COCOS",
        "messageDetail":"Assert Exception: itr->get_balance() >=20a3cb51b5f6471bb5747456a6550c48800f949355651d"
    }
}

Contract information query(No query interface for mobile terminal)

Interface name

queryContract

Request parameter

Parameter
Type
Must or Not
Description

nameOrId

Sting

M

Contract name or ID

Example for data format response:

{
    "code":1,
    "data":{
        "check_contract_authority":false,
        "abi_actions":[
            {
                "name":"add_num",
                "arglist":[
                    "num1",
                    "num2"
                ]
            },
            {
                "name":"init",
                "arglist":[

                ]
            },
            {
                "name":"log_pubdata",
                "arglist":[

                ]
            }
        ],
        "contract_authority":"COCOS5skVs12sjHtEvsKEpMfwiSvjkrubPKYKhBjKtX4bFBki4xiDvJ",
        "contract_data":{
            "num":20
        },
        "contract_data_type":[
            {
                "key_type":"string",
                "key":"num",
                "value_type":"init",
                "value":20
            }
        ],
        "create_date":"2019/03/27 20:00:00",
        "current_version":"4853897d105a2f3c020bc0ec47ba12e33a2c3ccf24e68f93b922bf8917f61355",
        "id":"1.16.15",
        "lua_code":"-- English 
-- The digit that Cocos currency precise to, available for currency information query by chain
-- rate parameter error updates
-- COCOS_ACCURACY = 100000 
function init() 
assert(chainhelper:is_owner(),'no auth')
read_list = {public_data={num=true}} 
chainhelper:read_chain() 
public_data.num = 0 
write_list = {public_data={num=true}} 
chainhelper:write_chain() 
end 

function add_num(num1,num2) 
read_list = {public_data={num=true}}
chainhelper:read_chain()

pub_num = tonumber(public_data.num) 
chainhelper:log(string.format("num_add the pub_num value is:%d",pub_num))

num1 = tonumber(num1) 
add_num = num1 + num2 

chainhelper:log(string.format("num_add the add_num value is:%d",add_num))

-- Enter the added value
public_data.num = add_num 
write_list = {public_data={num=true}} 
chainhelper:write_chain() 
end

-- Output the run-able number
function log_pubdata() 
read_list = {public_data={num=true}}
chainhelper:read_chain() 

pub_num = tonumber(public_data.num) 
chainhelper:log(string.format("log_pubdata the public_data value is:%d",pub_num))

write_list = {public_data={num=true}} 
chainhelper:write_chain() 
end",
        "contract_name":"contract.syling",
        "owner_account_name":"syling"
    }
}

The contract does not exist:

{
    "code":145,
    "message":"The contract (contract.sylin) does not exist",
    "error":{
        "code":15,
        "message":"Assert Exception: contract_itr != con_index.end(): The contract (contract.sylin) does not exist"
    }
}

Query account contract date(No query interface for mobile terminal)

Interface name

queryAccountContractData
Request parameter

Parameter
Type
Must or Not
Description

account

Sting

M

Account name or ID

contractNameOrId

Sting

M

Contract name or ID

Example for data format response:

{
    "code":1,
    "data":{
        "id":"1.17.14",
        "owner":"1.2.62",
        "contract_id":"1.16.15",
        "contract_data":{

        },
        "contract_data_type":[

        ],
        "contract_name":"contract.syling",
        "owner_account_name":"syling"
    }
}

Account not found:

{
    "code":104,
    "message":"sylingjj Account not found",
    "error":{
        "message":"sylingjj Account not found"
    }
}

The contract does not exist:

{
    "code":145,
    "message":"The contract (contract.sylingkk) does not exist",
    "error":{
        "code":39,
        "message":"Assert Exception: contract_itr != con_index.end(): The contract (contract.sylingkk) does not exist"
    }
}

Query account Info

Interface name

queryAccountInfo

Request parameter

Parameter
Type
Must or Not
Description

account

sting

M

Account name or ID

Example for data format response:

{
    "code":1,
    "data":{
        "account":{
            "id":"1.2.139",
            "membership_expiration_date":"1970-01-01T00:00:00",
            "registrar":"1.2.17",
            "referrer":"1.2.17",
            "lifetime_referrer":"1.2.17",
            "network_fee_percentage":2000,
            "lifetime_referrer_fee_percentage":3000,
            "referrer_rewards_percentage":5000,
            "name":"gnkhandsome2",
            "owner":{
                "weight_threshold":1,
                "account_auths":[

                ],
                "key_auths":[
                    [
                        "COCOS5n9n3eT83AsYnU7smuTQw55iGMkaucetnzmtLoFWbF2cr7YXzd",
                        1
                    ]
                ],
                "address_auths":[

                ]
            },
            "active":{
                "weight_threshold":1,
                "account_auths":[

                ],
                "key_auths":[
                    [
                        "COCOS61qJmvPif4seDKUjEkoL9qUP9cSvwBvgme5djcK8thuUS6o4Mg",
                        1
                    ]
                ],
                "address_auths":[

                ]
            },
            "options":{
                "memo_key":"COCOS61qJmvPif4seDKUjEkoL9qUP9cSvwBvgme5djcK8thuUS6o4Mg",
                "voting_account":"1.2.5",
                "num_witness":0,
                "num_committee":0,
                "votes":[

                ],
                "extensions":[

                ]
            },
            "statistics":"2.6.139",
            "contract_asset_locked":{
                "locked_total":[

                ],
                "lock_details":[

                ]
            },
            "whitelisting_accounts":[

            ],
            "blacklisting_accounts":[

            ],
            "whitelisted_accounts":[

            ],
            "blacklisted_accounts":[

            ],
            "owner_special_authority":[
                0,
                {

                }
            ],
            "active_special_authority":[
                0,
                {

                }
            ],
            "top_n_control_flags":0
        },
        "statistics":{
            "id":"2.6.139",
            "owner":"1.2.139",
            "most_recent_op":"2.9.2850",
            "total_ops":37,
            "removed_ops":0,
            "total_core_in_orders":0,
            "lifetime_fees_paid":2881770,
            "pending_fees":0,
            "pending_vested_fees":0
        },
        "registrar_name":"official-account",
        "referrer_name":"official-account",
        "lifetime_referrer_name":"official-account",
        "votes":[

        ],
        "balances":[
            {
                "id":"2.5.131",
                "owner":"1.2.139",
                "asset_type":"1.3.0",
                "balance":453190
            },
            {
                "id":"2.5.142",
                "owner":"1.2.139",
                "asset_type":"1.3.2",
                "balance":6296404
            }
        ],
        "vesting_balances":[

        ],
        "limit_orders":[

        ],
        "call_orders":[

        ],
        "settle_orders":[

        ],
        "proposals":[

        ],
        "assets":[

        ],
        "withdraws":[

        ]
    }
}

Account not found:

{
    "code":104,
    "message":"1.2.666 Account not found",
    "error":{
        "message":"1.2.666 Account not found"
    }
}

Get account info

Interface name

getAccountInfo

Example for data format response(No“locked” “mode” field for mobile terminal)

{
    "account_id":"1.2.136",
    "locked":false,
    "account_name":"gnkhandsome1",
    "mode":"account"
}

Account not found:

{
    "account_id":"",
    "locked":true,
    "account_name":"",
    "mode":"account"
}

Query NH Assets

Interface name

queryNHAssets

Request parameter

Parameter
Type
Must or Not
Description

NHAssetIds(array)

array

M

NH Assets hash or ID

Example for data format response

{
    "code":1,
    "data":[
        {
            "id":"4.2.11",
            "nh_hash":"866c7e61648c1cc7d6df2b3e0c532c4d8e470d152c0f88c6a2dda591f27f8f07",
            "nh_asset_creator":"1.2.38",
            "nh_asset_owner":"1.2.38",
            "nh_asset_active":"1.2.38",
            "authority_account":"1.2.38",
            "asset_qualifier":"COCOS",
            "world_view":"joy",
            "base_describe":{

            },
            "parent":[

            ],
            "child":[

            ],
            "describe_with_contract":{

            },
            "create_time":"2019/03/06 16:03:05",
            "limit_list":[

            ],
            "limit_type":"black_list",
            "nh_asset_creator_name":"reedhong",
            "nh_asset_owner_name":"reedhong",
            "nh_asset_active_name":"reedhong",
            "authority_account_name":"reedhong"
        }
    ]
}

NH Assets do not exist:

{
    "code":147,
    "message":"4.2.4141 NHAsset do not exist"
}

Query account NH Assets Orders

Interface name

queryAccountNHAssetOrders

Request parameter

Parameter
Type
Must or Not
Description

account

Sting

M

Account

Page

int

M

Page

pageSize

int

M

Amount

Example for data format response:

{
    "code":1,
    "data":[
        {
            "id":"4.3.16",
            "seller":"1.2.136",
            "otcaccount":"1.2.40",
            "nh_asset_id":"4.2.187",
            "asset_qualifier":"GNKHANDSOME",
            "world_view":"GNKHAND",
            "base_describe":"{"name":"GNKHANDSOME"}",
            "nh_hash":"888e7617b8a55f9246d6788ae104133a7dbf31229653da31d72200b731fee6ce",
            "price":{
                "amount":1000000,
                "asset_id":"1.3.0"
            },
            "memo":"",
            "expiration":"2019/04/24 13:51:00"
        }
    ],
    "total":3
}

Query NH Asset orders of the universal network

Interface name

queryNHAssetOrders

Request parameter

Parameter
Type
Must or Not
Description

assetIds

Sting

M

Assets ID or name

worldViews

Sting

N

Worldview ID or name

baseDescribe

Sting

N

baseDescribe

page

int

M

Page

pageSize

int

M

Amount

Example for data format response:

{
    "code":1,
    "data":[
        {
            "id":"4.3.16",
            "seller":"1.2.136",
            "otcaccount":"1.2.40",
            "nh_asset_id":"4.2.187",
            "asset_qualifier":"GNKHANDSOME",
            "world_view":"GNKHAND",
            "base_describe":"{"name":"GNKHANDSOME"}",
            "nh_hash":"888e7617b8a55f9246d6788ae104133a7dbf31229653da31d72200b731fee6ce",
            "price":{
                "amount":1000000,
                "asset_id":"1.3.0"
            },
            "memo":"",
            "expiration":"2019/04/24 13:51:00"
        }
    ],
    "total":1
}

Query account NH Assets

Interface name

queryAccountNHAssets

Request parameter

Parameter
Type
Must or Not
Description

account

Sting

M

Query account

worldViews(array)

array

N

The worldviews in query are separated by“,".

page

int

M

Page

pageSize

int

M

Amount

Example for data format response:

{
    "code":1,
    "data":[
        {
            "id":"4.2.189",
            "nh_hash":"8e8e7617b8a55f9246d6788ae104133a7dbf31229653da31d72200b731fee6ce",
            "nh_asset_creator":"1.2.139",
            "nh_asset_owner":"1.2.136",
            "nh_asset_active":"1.2.136",
            "authority_account":"1.2.136",
            "asset_qualifier":"COCOS",
            "world_view":"GNKHAND",
            "base_describe":"{"name":"GNKHANDSOME"}",
            "parent":[

            ],
            "child":[

            ],
            "describe_with_contract":[

            ],
            "create_time":"2019-04-10T11:34:55",
            "limit_list":[

            ],
            "limit_type":"black_list"
        }
    ],
    "total":1
}

Decode memo

interface name

decodeMemo

Request parameter

Type
Must or Not
Description

Sting

M

Memo transfers in the following format data directly:

{
    "from":"COCOS6G55VgR94GZmELS4UHEf2eVggmhPRnWLTWgGiEmzuBKdvEwoAB",
    "to":"COCOS61qJmvPif4seDKUjEkoL9qUP9cSvwBvgme5djcK8thuUS6o4Mg",
    "nonce":"12970368479715836292",
    "message":"b9b37e032e205a78ce7238bfdeebc791"
}

Code example

exports.decodeMemo = function(successCallBack,failCallBack){
        var memo = {
            from:"COCOS6P1TAsfLCoPpyzjRtcgDTXL62oCxiZK3yYMer2hZGJ4ZvoRhx6",
            to:"COCOS61qJmvPif4seDKUjEkoL9qUP9cSvwBvgme5djcK8thuUS6o4Mg",
            nonce:3354427411,
            message:"06659ec71b56cef9fcdb86d3fe30330f"
            }
        BcxWeb.decodeMemo(memo).then(result => {
            console.log('decodeMemo - successCallBack- result',JSON.stringify(result))
            successCallBack(result);
        }).catch(error => {
            console.log('decodeMemo - failCallBack- result',JSON.stringify(error))
            failCallBack(error);
        });
    }

Example for data format response(No 'isMine' field for mobile terminal)

{
    "code":1,
    "data" :{
      "isMine":0,
        "text":"ress"
    }
}

NH Assets transfer(Mobile only provided trx_id field)

Interface name

transferNHAsset

Request parameter

Parameter
Type
Must or Not
Description

toAccount

Sting

M

Transfer target account

NHAssetIds(array)

array

M

NH Assets ID

Example for data format response:

{
    "code":1,
    "data":[
        {
            "real_running_time":125
      }
    ],
    "trx_data":{
        "trx_id":""b50b2cf155e91df08e7e0e3756ae76b423679e71f5cf633fa05dedeeb96204fd"",
        "block_num":5322683
}
}

Account not found:

{
    "code":104,
    "message":"XXX Account not found",
    "error":{
        "message":"XXX Account not found"
    }
}

NHAssets do not exist:

{
    "code":147,
    "message":"XXX NHAsset do not exist"
}

Purchase NH Assets

Interface name

fillNHAssetOrder

Request parameter

Parameter
Type
Must or Not
Description

orderId

Sting

M

Order ID

onlyGetFee

boolean

M

true:Only get the operating fee of this purchase of NH Assets;false:Purchase NH Assets

True:
False:

Example for data format response:

Data return for only get operation fee for NH Assets purchase(onlyGetFee = true):

{
    "code":1,
    "data":{
        "fee_amount":0,
        "fee_symbol":"COCOS"
    }
}

Data return for purchase assets purchase(onlyGetFee = true)(Mobile terminal only offered trx_id field):

{
    "code":1,
    "data":[
        {
            "result": "4.2.192",
            "real_running_time":204
        }
    ],
    "trx_data":{
    "trx_id":"01e7036237896f9069905d4fc9c5d86a55bb2d0ef2fca43e6df5d5123766f223",
        "block_num":5409694
    }
}

Insufficient balance:

{
    "code":0,
    "message":"Assert Exception: insufficient_balance: Insufficieble to pay 1000 COCOS from gnkhandsome2 to syling" ",
    "error":{
        "code":31,
        "message":"Assert Exception: insufficient_balance: Insufficient Balance: 3.53190 COCOS, unable to transfer '1000 COCOS' from account 'gnkhandsome2' to 'syling' Unable",
        "messageDetail":"Assert Exception: insufficient_balance: Insufficient Balance: 3.53190 COCOS, unable to transfer '1000 COCOS' from account 'gnkhandsome2' to 'syling"]}"
    }
}

Not logged in:

{
    "code":-11,
    "message":"Please login first"
}

Query account balance

Interface name
queryAccountBalances

Request parameter

Parameter
Type
Must or Not
Description

assetId

Sting

M

Assets identity or ID

account

Sting

M

Account name

Example for data format response:

Data return for query asset balance:

{
 "code":1,
    "data":{
        "COCOS":"8949.18901"
    }
}

Network connection failed:

{
    "code":102,
    "message":"It doesnt connect to the server.",
    "data":{
        "COCOS":"0"
    }
}

9.3 DApp Development Interface


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.