7.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

Code
Message
Description

300

Chain sync error, please check your system clock

301

RPC connection failed. Please check your network

1

None

Operation succeeded

0

failed

The operation failed, and the error status description is not fixed. You can directly prompt res.message or to prompt the operation failure.

101

Parameter is missing

1011

Parameter error

102

The network is busy, please check your network connection

103

Please enter the correct account name(/^a-z{4,63}/$)

104

XX not found

105

wrong password

106

The account is already unlocked

107

Please import the private key

108

User 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)

109

Please enter the correct private key

110

The private key has no account information

111

Please login first

112

Must have owner permission to change the password, please confirm that you imported the ownerPrivateKey

113

Please enter the correct original/temporary password

114

Account is locked or not logged in

115

There is no asset XX on block chain

116

Account receivable does not exist

117

The current asset precision is configured as X ,and the decimal cannot exceed X

118

Encrypt memo failed

119

Expiry of the transaction

120

Error fetching account record

121

block and transaction information cannot be found

122

Parameter blockOrTXID is incorrect

123

Parameter account can not be empty

124

Receivables account name can not be empty

125

Users do not own XX assets

127

No reward available

129

Parameter ‘memo’ can not be empty memo

130

Please enter the correct contract name(/^a-z{4,63}$/)

131

Parameter ‘worldView’ can not be empty

133

Parameter ‘toAccount’ can not be empty toAccount

135

Please check parameter data type

136

Parameter ‘orderId’ can not be empty

137

Parameter ‘NHAssetHashOrIds’ can not be empty

138

Parameter ‘url’ can not be empty

139

Node address must start with ws:// or wss://

140

API server node address already exists

141

Please check the data in parameter NHAssets

142

Please check the data type of parameter NHAssets

144

Your current batch creation / deletion / transfer number is X , and batch operations can not exceed X

145

XX contract not found

146

The account does not contain information about the contract

147

NHAsset do not exist

148

Request timeout, please try to unlock the account or login the account

149

This wallet has already been imported

150

Key import error

151

File saving is not supported

152

Invalid backup to download conversion

153

Please unlock your wallet first

154

Please restore your wallet first

155

Your browser may not support wallet file recovery

156

The wallet has been imported. Do not repeat import

157

Can’t delete wallet, does not exist in index

158

Imported Wallet core assets can not be XX , and it should be XX

159

Account exists

160

You are not the creator of the Asset XX .

161

Orders do not exist

162

The asset already exists

163

The wallet already exists. Please try importing the private key

164

worldViews do not exist

165

There is no wallet account information on the chain

166

The Wallet Chain ID does not match the current chain configuration information. The chain ID of the wallet is: XX

167

The current contract version ID was not found

168

This subscription does not exist

169

Method does not exist

Project

CocosBCXWallet

Open Source Address

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

7.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.