A Beginner’s Guide to SideDBs and Private Data for Hyperledger Fabric Nodejs Chaincode
The latest v1.2 release of Hyperledger Fabric introduces private data stored in SideDBs. This solution offers you the possibility to build “GDPR compliant” blockchain solutions. The following article will show you how to use these private DBs. If you are not yet familiar with the concept of private data on Hyperledger Fabric, check out the previous article written by Jonas Snellinckx.
Note: This is a technical article. We will make use of our Hyperledger Fabric Network boilerplate and our chaincode utils on Github.
Private data use case
To demonstrate the use of private collections, we’ll use the classic car example. The
initLedger function will create ten new cars in our collection. All these cars can be accessed and view by anyone in the network. Let’s create a private repository we only want to share with one other garage we own.
To get started, we first need a collections configuration file
collections_config.json which includes the collection name and policy. The policy is similar to an endorsement, this allows us to use the already existing policy logic like OR, AND, … operators.
Our Hyperledger boilerplate which we are using already contains a function to create and query for private data. This is the original
For adding data to a private collection (
carCollection ), we just need to specify to which collection we want to add the data.
Next, for querying a car we have to specify the private collection we want query.
For deleting and updating objects, you do the exact same.
Chaincode best practices
It will certainly occur that part of your data will be stored on-chain visible for anyone in the network. However, some of the data is private and will be stored in the private collection accessible by the peers defined in the collection config.
We suggest using the same key for storing the object in the public and private collection which makes it easier for retrieving the data later on.
stubHelper implements a
generateUUID that creates a deterministic ID for storing an object.
Interested in starting your own blockchain project, but don’t know how? Do you need help starting your token sale or having one audited? Get in touch with TheLedger.
We demonstrated here, how easy it is to write chaincode using our package. You don’t have to, but it speeds things up quite a bit. These examples can help you get started, if you want to read our documentation, you can check out our github. We would also encourage you to contribute and make this package better. 👌