All Products
Search
Document Center

Blockchain as a Service:Node.js SDK usage example

Last Updated:Mar 31, 2026

The marbles sample shows how to deploy and run a Hyperledger Fabric Node.js SDK application on Alibaba Cloud Blockchain as a Service (BaaS). The sample includes a chaincode and a browser-based marble-trading game. This guide walks you through the full setup — from configuring the SDK connection profile to playing the game in your browser.

Prerequisites

Before you begin, ensure that you have:

  • A running Hyperledger Fabric network on BaaS with at least one organization and channel

  • The SDK connection profile (connection-profile-standard.json) downloaded from the BaaS console

  • Node.js v8 and npm installed

To verify your versions:

$ node --version
V8.11.2

$ npm --version
5.6.0

How it works

The setup follows three sequential steps:

  1. Download the sample package and configure the connection profile with your organization's Certificate Authority (CA) credentials.

  2. Upload and instantiate the marbles chaincode on your BaaS channel.

  3. Start the app, connect it to your chaincode, and start trading marbles.

Step 1: Download and configure the sample

1.1 Download the package

Download node-sdk-demo-1.4.5 and extract it to any directory. Copy your connection-profile-standard.json (downloaded from the BaaS console) into the node-sdk-demo/config directory.

The final directory structure looks like this:

node sdk layout

1.2 Configure the connection profile

The connection profile tells the Node.js SDK how to connect to your Fabric network. You need to add your organization's CA credentials to the certificateAuthorities section so the SDK can enroll users and obtain certificates.

Open config/connection-profile-standard.json and add a registrar entry under the CA that belongs to your organization:

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

For example, if the username is user and the password is user-secret, and the user belongs to the test10 organization, add the credentials to the CA entry ca1.test10.aliyunbaas.top.

The modified certificateAuthorities section looks like this:

connection-profile-standard
Tip: Paste the JSON into jsonlint.com to format and validate it before saving.

Step 2: Upload the chaincode

Upload node-sdk-demo/chaincode/marbles_v4.cc to BaaS, then instantiate it on your channel. For detailed steps, see Deploy chaincodes.

Step 3: Run the marbles app

3.1 Install dependencies and start the app

From the node-sdk-demo directory, install the npm dependencies and start the app:

npm install --registry http://registry.npmmirror.com
gulp marbles_baas

When the app starts successfully, you see the following output:

Debug: Open your browser to http://localhost:3001 and login to tweak settings for startup

Open http://localhost:3001 in your browser. If prompted for a password, enter admin.

3.2 Configure the chaincode settings

The app opens on a setup guide page. Select Guided mode. It automatically jumps to step 3, where you configure the chaincode connection:

image.png

Fill in the following fields:

FieldValue
channelThe channel name where you uploaded marbles_v4 (for example, first-channel)
chaincode_idmarbles
chaincode_versionv4

Click Try Again. If the chaincode is detected successfully, you see the following page:

image.png

If the check fails, confirm that the chaincode has been uploaded and instantiated on the correct channel.

3.3 Play the game

Close the dialog box to start the marble-trading game. Drag marbles from one user to another to transfer assets. Click + next to a user to add a marble, or drag a marble to the trash to delete it.

image.png

Expected warnings

When the app starts, you may see error logs similar to:

Missing 'chaincodeId' parameter

This is expected. The connection-profile-standard.json generated by BaaS follows the standard Fabric connection profile format, which does not include chaincode-specific configuration — that is handled through the marbles setup guide. These logs do not affect the app's operation.

What's next