The sample program for the Fabric Nodejs SDK is based on marbles from community, which contains a chaincode and a web game. Here’s how to run it in BaaS.
Marbles relies on
Nodejs v8 version and
npm, and confirms that Nodejs and npm have been successfully installed by the following command.
$ node --version
$ npm --version
Download node-sdk-demo-1.4.5 to any directory and unzip it. Copy the SDK configuration file
connection-profile-standard.json to the directory
node-sdk-demo/config. The final directory structure is as follows:
Modify the configuration file
config/connection-profile-standard.json:Construct the username and password into the following JSON content and add it to the corresponding
For example, if the username and password created in the blockchain organization page are:
user-secret, and the user is from the
test10 organization, then the user information need to be added to CA:
ca1.test10.aliyunbaas.top. The modified configuration file is shown below:
Tip: Formatting the json file is easier to edit and can be formatted using the online service: https://jsonlint.com/. After editing, we recommend to use the formatting tool to monitor whether the json format is legal.
Upload the chaincode
node-sdk-demo/chaincode/marbles_v4.cc to BaaS and instantiate it. For the upload method, please see the Deploy Chaincode.
Run the following command to install the marbles dependency and start the marbles app:
Npm install --registry http://registry.npm.taobao.org
When you see the following output, the marbles app has started:
Debug: Open your browser to http://localhost:3001 and login to tweak settings for startup
Open your browser to http://localhost:3001/ to access the marbles’s web. If it asks for a password, type
Note: Since the connection-profile-standard.json generated by BaaS is a standard fabric configuration file, the configuration information of chaincode is not included (this configuration is a personalized configuration of marbles), so you may see some error logs such as ‘Missing ‘chaincodeId’ parameter’, these error logs are expected and do not affect the operation of the marbles.
Next, is going to configure the information about the chaincode in the marbles guide page, so select the “Guided” mode:
Automatically jump to the third step and start configuring the Chaincode information:
- channel: Enter the channel name of the uploaded marbles_v4, such as first-channel.
- chaincode_id: Enter marbles.
- chaincode_version: Enter v4.
After the input is complete, click “Try Again”. If the chaincode is successfully detected, you will see the following page. If the check fails, please reconfirm whether the chaincode has been uploaded and the it has been instantiated.
At this point, the configuration is complete, close the dialog box window and start play. This is an example program for transferring colored marble assets between different users by draging the marbles from one user to another. Click on the “+” to the right of the user to add a marble asset to the user. Drag the marble to the trash to delete the asset.