All Products
Search
Document Center

Use Fabric Nodejs SDK (marbles)

Last Updated: Apr 28, 2019

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.

Installing Nodejs and NPM

Marbles relies on Nodejs v8 version and npm, and confirms that Nodejs and npm have been successfully installed by the following command.

  1. $ node --version
  2. V8.11.2
  3. $ npm --version
  4. 5.6.0

Download the sample program

Download https://baas-sdk.oss-cn-hangzhou.aliyuncs.com/node-sdk-demo-1.0.1.tar.gz 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:

node sdk layout

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

  1. "registrar": [
  2. {
  3. "enrollId": "user",
  4. "enrollSecret": "user-secret"
  5. }
  6. ],

For example, if the username and password created in the blockchain organization page are: user/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.

connection-profile-standard

Upload chaincode

Upload the chaincode node-sdk-demo/chaincode/marbles_v4.cc to BaaS and instantiate it. For the upload method, please see the Deploy Chaincode.

Running the sample program

Run the following command to install the marbles dependency and start the marbles app:

  1. Npm install --registry http://registry.npm.taobao.org
  2. Gulp marbles_baas

When you see the following output, the marbles app has started:

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

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:

marble guide

Automatically jump to the third step and start configuring the Chaincode information:

marble chaincode

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

chaincode ok

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.

marbles running

More information about marbles can be found in Community Documentation. More instructions on using the Nodejs SDK can be found in the community fabric-sdk-node.