First Attempt on BSN: Deploy a Sample Fabric Chaincode in BSN Testnet


BSN (Blockchain-based Service Network) was first announced last year. Since then, they keep deploying nodes in China and across the world, and launched international portal for services on a variety of blockchain frameworks. Here is my first experience on their permissioned services on Hyperledger Fabric through their Testnet. In this article I first provided a very brief introduction about BSN, and made a quick demonstration on how to deploy a standard smart contract package (chaincode) on the Hyperledger Fabric framework integrated into the BSN.

Quick Overview of BSN

To understand more about BSN, the best source of information is from BSN. Here you can find the official information. Here is a quick overview on it.

Difference between using Fabric natively and Fabric adapted in BSN
BSN Connection Flow (Source: BSN User Manual v1.3.0 link)

Demonstration Arrangement

Here we will demonstrate how to deploy a sample chaincode on BSN Testnet, and how to access (invoke) chaincode functions using PCN Gateway API/SDK.

BSN Account

We need a user account before using BSN. Simply register a new account in BSN Global site ( With this account you can test several services free of charge, and here we are using Permissioned Service Testnet.


In real life, BSN permissioned services allow developer to select the framework (e.g. Hyperledger Fabric or FISCO BCOS), sites and the number of peers in each site. Application owners are then charged by the site locations, quantity of peer, storage and data volume, on a monthly basis.


We are using a sample chaincode for our demonstration. This chaincode is adapted from the Simple Asset Chaincode (SACC) provided in fabric-samples/chaincode/. This chaincode comes with two functions,

  • get(): retrieve the value from the ledger based on the given key


After the chaincode is deployed in BSN, credentials for the Testnet are downloaded, and we can build our application accessing this chaincode, that is, invoking chaincode functions. Currently PCN Gateway supports Python, Java, Go and CSharp. In this demonstration we are using Python SDK. Python 3 is needed for the demonstration, and the SDK setup will load other packages required.

Demonstration Detail

Prepare Chaincode Package

Assuming you have fabric-samples/ well downloaded in your computer and a proper Go environment is set.

cd fabric-samples/chaincode/
cp -r sacc testBSN
cd testBSN
zip -r testBSN/

Upload and Deploy Chaincode Package

Login BSN Global ( In the left list choose Permissioned Services and Testnet Services.

Successful deployment of chaincode in Testnet
  • Access URL: This is the BSN PCN Gateway to access the Testnet.
  • UserCode and APPCode: We specify both the user code and application code in our application.
  • Chaincode deployment name: This refers to the deployment of our chaincode package.

Access Application / Invoking Chaincode Functions with Python SDK

First, take a look at the credential material downloaded and unzipped. We place it inside the testcert/ directory.

from bsn_sdk_py.client.config import Config
from bsn_sdk_py.client.fabric_client import FabricClient
nodeApi = ""
user_code = "USER0003202009052048235246180"
app_code = "app003eaab3197d3f342fdb217563493efd3c8"
chaincode = "cc_8b6c2a8007904790a020accf8bbb19f7"
app_public_cert_path = "/home/ubuntu/testcert/gatewayCert/gateway_public_cert_secp256r1.pem"
user_private_cert_path = "/home/ubuntu/testcert/userAppCert/secp256r1/private_key.pem"
mspDir = "/home/ubuntu/testcert/fabricMsp"
httpcert = ""
c = Config(user_code, app_code, nodeApi, mspDir, httpcert, app_public_cert_path, user_private_cert_path)client = FabricClient()
result = client.req_chain_code(chaincode,'set','',['name','Peter'])
Comparison: using peer command without BSN.
result = client.req_chain_code(chaincode,'get','',['name'])
Comparison: using peer command without BSN.


This is just a demonstration on how the permissioned blockchain like Hyperledger Fabric is adapted into the BSN environment. As you can see I do not need to care the fabric network setup: all are predefined and done by BSN. I simply upload the chaincode and it can run in BSN. You also notice that BSN has adapted and integrated these permissioned blockchain frameworks into their environment, and provides a unified way when accessing the applications deployed in BSN. There are other interesting services in BSN and I will share with you once I have done some more tests.

Visit for all my works. Reach me on or follow me @kctheservant in Twitter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store