8.1 JS-SDK

The Javascript API for integration with COCOS-BCX-based blockchain using the COCOS-BCX RPC API.

Class Library Reference

Introducing API files

<script type="text/javascript" src="bcx.min.js"></script>

Instantiating the class library object

var bcx=new BCX({
            default_ws_node:”ws://XXXXXXXXX” //node rpc address, optional. If you do not specify this, it will automatically connect to the fastest node in ws_node_list
            ws_node_list:[{url:"ws://xxxxxxx",name:"xxxxx"}]//API server node list, required
            faucet_url:"http://xxx.xxx.xxx.xxx:xxxx", //Registration
            networks:[{
                core_asset:"xxx",//core asset symbol
                chain_id:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"//chain id   
            }], 
            auto_reconnect:false,//Whether to connect automatically when RPC is disconnected, the default is true
            app_keys:["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]//Contract authorization. Do not need to configure this if there is no contract authorization.
     })

Instance of call - transfer

bcx.transferAsset({
            fromAccount: 'test1',
            toAccount: 'test2',
            amount: amount,
            assetId: 'COCOS',
            feeAssetId: 'COCOS',
            memo: memo,
            onlyGetFee: false,
        }).then(function (res) {
             console.log('transferAsset res',res);
        })

API User Guide

  1. There is one optional parameter callback unless otherwise specified.
The result returned by callback is an Object with an structure of {code:0,message:""}. If it is code=1, it means the result is success, and there is no message status description. If it is Code!=1, it means that the result is failure, the message is the description of the failure status.
  2. ​There is only one parameter unless otherwise specified. The parameter is an object that contains all relevant parameters, including callback.
    Example:
bcl.getPrivateKey({
     callback:res=>{}
})
  1. In addition to the subscription interface, other interfaces return a promise object when not passing callback parameter.
  2. The parameter type of the interface is a string unless otherwise specified.
  3. The parameter of the interface cannot be empty unless otherwise specified. Callback is an optional parameter.
    6.The searching interface returns a data instance: {code:1,data:[]}
  4. The data returned by other interfaces will have an additional data field trxData with a value of one object.
    Example:
trx_data:{
 block_num:*****,//Block height
 trx_id:"************************"//Transaction ID
}
  1. ​If a non-query interface involves associated ID business (such as the ID generated by creating the NH asset), the data returned will contain the data object.
    Example:
data:{
  real_running_time: 387//Running time
  result: "4.2.288"//Associated business id
}

Status Code

Description

CodeMessageDescription
300Chain sync error, please check your system clock
301RPC connection failed. Please check your network
1NoneOperation succeeded
0failedThe operation failed, and the error status description is not fixed. You can directly prompt res.message or to prompt the operation failure.
101Parameter is missing
1011Parameter error
102The network is busy, please check your network connection
103Please enter the correct account name(/^a-z{4,63}/$)
104XX not found
105wrong password
106The account is already unlocked
107Please import the private key
108User name or password error (please confirm that your account is registered in account mode, and the account registered in wallet mode cannot be logged in using account mode)
109Please enter the correct private key
110The private key has no account information
111Please login first
112Must have owner permission to change the password, please confirm that you imported the ownerPrivateKey
113Please enter the correct original/temporary password
114Account is locked or not logged in
115There is no asset XX on block chain
116Account receivable does not exist
117The current asset precision is configured as X ,and the decimal cannot exceed X
118Encrypt memo failed
119Expiry of the transaction
120Error fetching account record
121block and transaction information cannot be found
122Parameter blockOrTXID is incorrect
123Parameter account can not be empty
124Receivables account name can not be empty
125Users do not own XX assets
127No reward available
129Parameter ‘memo’ can not be empty memo
130Please enter the correct contract name(/^a-z{4,63}$/)
131Parameter ‘worldView’ can not be empty
133Parameter ‘toAccount’ can not be empty toAccount
135Please check parameter data type
136Parameter ‘orderId’ can not be empty
137Parameter ‘NHAssetHashOrIds’ can not be empty
138Parameter ‘url’ can not be empty
139Node address must start with ws:// or wss://
140API server node address already exists
141Please check the data in parameter NHAssets
142Please check the data type of parameter NHAssets
144Your current batch creation / deletion / transfer number is X , and batch operations can not exceed X
145XX contract not found
146The account does not contain information about the contract
147NHAsset do not exist
148Request timeout, please try to unlock the account or login the account
149This wallet has already been imported
150Key import error
151File saving is not supported
152Invalid backup to download conversion
153Please unlock your wallet first
154Please restore your wallet first
155Your browser may not support wallet file recovery
156The wallet has been imported. Do not repeat import
157Can’t delete wallet, does not exist in index
158Imported Wallet core assets can not be XX , and it should be XX
159Account exists
160You are not the creator of the Asset XX .
161Orders do not exist
162The asset already exists
163The wallet already exists. Please try importing the private key
164worldViews do not exist
165There is no wallet account information on the chain
166The Wallet Chain ID does not match the current chain configuration information. The chain ID of the wallet is: XX
167The current contract version ID was not found
168This subscription does not exist
169Method does not exist

Project

CocosBCXWallet

Open Source Address

https://github.com/Cocos-BCX/JSSDK

Updated 5 months ago


WHAT'S NEXT LABEL

8.2 iOS-SDK

8.1 JS-SDK


The Javascript API for integration with COCOS-BCX-based blockchain using the COCOS-BCX RPC API.

Suggested Edits are limited on API Reference Pages

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