9.3 DApp开发接口

获取账户名称

window.BcxWeb.account_name

获取转账费用

接口名称

transferAsset

请求参数

参数名
类型
是否必须
描述

fromAccount

Sting

M

发送方

toAccount

Sting

M

接收方

amount

String

M

金额

assetId

String

M

资产ID (如:X.X.X)或 代币符号(如:COCOS)

memo

String

N

备注

feeAssetId

String

M

支付手续费的代币资产符号

isPropose

boolean

M

是否发起提议

onlyGetFee

boolean

M

true:只获取操作费用;false:进行转账操作

响应数据格式示例:

只获取转账费用的数据返回(onlyGetFee = true):

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

转账操作的数据返回(onlyGetFee = false)(移动端只提供trx_id字段):

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

余额不足:

{
    "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"]}"
    }
}

未登录

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

memo 加密失败

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

合约方法调用

接口名称

callContractFunction

请求参数

参数名
类型
是否必须
描述

nameOrId

Sting

M

合约name或ID

functionName

Sting

M

目标函数名

valueList(array)

array

M

参数列表

runtime l

ong

N

runTime(单位毫秒)

onlyGetFee

boolean

M

true:只获取操作费用;false:进行转账操作

响应数据格式示例:
只获取本次操作的费用的数据返回(onlyGetFee = true):

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

本次操作的数据返回(onlyGetFee = false)(移动端只提供trx_id字段):

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

签名失败:

{
    "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]"
    }
}

余额不足

{
    "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"
    }
}

查询合约信息 (移动端不提供该查询接口)

接口名称

queryContract

请求参数

参数名
类型
是否必须
描述

nameOrId

Sting

M

合约name或ID

响应数据格式

{
    "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 
-- Cocos 币种精确位,通过链查询币种信息可得
-- rate 参数错误更新
-- 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))

-- 相加的值写进去
public_data.num = add_num 
write_list = {public_data={num=true}} 
chainhelper:write_chain() 
end

-- 输出数字 可以运行的
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"
    }
}

合约不存在:

{
    "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"
    }
}

查询账户合约信息 (移动端不提供该查询接口)

接口名称

queryAccountContractData

请求参数

参数名
类型
是否必须
描述

account

Sting

M

帐户名或id

contractNameOrId

Sting

M

合约name或ID

响应数据格式

{
    "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"
    }
}

账户不存在:

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

合约不存在:

{
    "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"
    }
}

查询账户信息

接口名称

queryAccountInfo

请求参数

参数名
类型
是否必须
描述

account

Sting

M

帐户名或id

响应数据格式

{
    "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":[

        ]
    }
}

账户不存在

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

获取当前账户信息

接口名称

getAccountInfo

响应数据格式(移动端无“locked”“mode”字段)

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

账户不存在

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

查询NH资产详细信息

接口名称

queryNHAssets

请求参数

参数名
类型
是否必须
描述

NHAssetIds(array)

array

M

Nh资产hash或id

响应数据格式

{
    "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资产不存在

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

查询账户下所拥有的NH资产售卖订单

接口名称

queryAccountNHAssetOrders

请求参数

参数名
类型
是否必须
描述

account

Sting

M

账户

page

int

M

页码

pageSize

int

M

查询数量

响应数据格式

{
    "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
}

查询全网NH资产售卖订单

接口名称

queryNHAssetOrders

请求参数

参数名
类型
是否必须
描述

assetIds

Sting

M

资产ID或资产符号

worldViews

Sting

N

世界观ID或世界观名

baseDescribe

Sting

N

baseDescribe

page

int

M

页码

pageSize

int

M

查询数量

响应数据格式

{
    "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
}

查询账户下所拥有的道具NH资产

接口名称

queryAccountNHAssets

请求参数

参数名
类型
是否必须
描述

account

Sting

M

查询账户

worldViews(array)

array

N

查询的世界观多个世界观用“,” 分开

page

int

M

页码

pageSize

int

M

查询数量

响应数据格式

{
    "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
}

交易备注解密

接口名称

decodeMemo

请求参数

类型
是否必须
描述

Sting

M

Memo直接传入以下格式数据:

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

示例代码

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);
        });
    }

响应数据格式 (移动端无 ‘isMine’ 字段)

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

NH资产转移 (移动端只提供trx_id字段)

接口名称

transferNHAsset

请求参数

参数名
类型
是否必须
描述

toAccount

Sting

M

转移目标账户

NHAssetIds(array)

array

M

nh资产Id

响应数据格式

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

账户不存在

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

NH资产不存在

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

购买NH资产

接口名称

fillNHAssetOrder

请求参数

参数名
类型
是否必须
描述

orderId

Sting

M

订单id

onlyGetFee

boolean

M

true:只获取本次购买nh资产的操作费用;false:进行购买nh资产操作

响应数据格式

只获取购买nh资产的操作费用数据返回(onlyGetFee = true):

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

购买nh资产操作的数据返回(onlyGetFee = false)(移动端只提供trx_id字段):

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

余额不足:

{
    "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"]}"
    }
}

未登录

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

获取账户余额

接口名称
queryAccountBalances

请求参数

参数名
类型
是否必须
描述

assetId

Sting

M

资产标识或id

account

Sting

M

账户名称

响应数据格式

获取资产余额的数据返回:

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

网络连接失败:

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

详情请看7.1 JS-SDK


9.3 DApp开发接口


Suggested Edits are limited on API Reference Pages

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