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

Introduction

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 (https://www.bsnbase.io). With this account you can test several services free of charge, and here we are using Permissioned Service Testnet.

Setup

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.

Chaincode

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

BSN PCN Gateway SDK

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.zip testBSN/

Upload and Deploy Chaincode Package

Login BSN Global (https://www.bsnbase.io). 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 = "http://119.8.103.189:4004"
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()
client.set_config(c)
result = client.req_chain_code(chaincode,'set','',['name','Peter'])
result.get('body').get('ccRes')
Comparison: using peer command without BSN.
result = client.req_chain_code(chaincode,'get','',['name'])
result.get('body').get('ccRes')
Comparison: using peer command without BSN.
client.get_ledger_info().get('body').get('height')client.req_chain_code(chaincode,'set','',['name','John'])client.get_ledger_info().get('body').get('height')

Summary

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 http://www.ledgertech.biz/kcarticles.html for all my works. Reach me on https://www.linkedin.com/in/ktam1/ 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