All Products
Search
Document Center

Blockchain as a Service:Use Fabric Nodejs SDK (marbles)

Last Updated:Sep 18, 2023

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.

$ node --version
V8.11.2

$ npm --version
5.6.0

Download the sample program

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:

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.

 "registrar": [
        {
            "enrollId": "user",
            "enrollSecret": "user-secret"
        }
  ],

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:

Note

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:

Npm install --registry http://registry.npmmirror.com
Gulp marbles_baas

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

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

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

image.png

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.

image.png

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.