Building a (Re)insurance blockchain network with Hyperledger Composer

Fabien Stepho
Sep 1, 2017 · 7 min read

Simple blockchain definition

A blockchain is essentially a ledger of records, of digitale events, shared/distributed between many different parties. It can only be updated by consensus of a majority of the participants in the system. And, once created, information can never be altered. The blockchain contains a certain an verifiable record of every single transaction ever made.


Some of the benefits that a blockchain platform could provide in a reinsurance network are :

  • Single version of an asset, thanks to the sharing/distributed ledger. Theses assets are then wrapped in the form of smart contract. For example assets could be risk, technical or financial account, claim.

Use case

The use case we are going to build is a claim processing for a Reinsurance Organization.

  • As a Reinsurance organization, I would like to see the finance related status of claims requested by my cedents
Image for post
Image for post
Reinsurance Network Participants

Developer guide for creating a Hyperledger Composer solution for reinsurance

This guide was written with the latest Hyperledger Composer on Ubuntu Linux running with Hyperledger Fabric v1.0. It was written based on the hyperledger official documentation and adapted for reinsurance domain.

This guide will help you to build a Hyperledger Composer blockchain solution. You will be able to execute transactions against a real Hyperledger Fabric blockchain network for Reinsurance Claims that interacts with a blockchain network.

Image for post
Image for post
Participants/Assets interactions that we are about to build

Installing Hyperledger Composer

Follow this Development Environment Install guide — As well as installing Composer, it has instructions to quickly build a Hyperledger Fabric blockchain environment (using Docker containers) which we will use on in this guide.

Creating the Reinsurance Claims Business Network Definition

The key concept for Composer is the business network definition (BND). It defines the data model, business (and transaction) logic and access control rules for the blockchain solution. It executes on Hyperledger Fabric. To create a business network definition, we need to create the project structure on disk.

The easiest way is to clone an existing sample business network. Open up a command prompt and clone the Composer sample networks GitHub repository from Hyperledger. For Linux, perform this as a non-root user.

> git clone

Then, make a copy of this directory in your project, called “reinsurance-network

> cp -r ./composer-sample-networks/packages/basic-sample-network/  ./reinsurance-network

You should now have a folder called reinsurance-network that we can start to modify. Using an Editor Code (like Visual Studio Code or Sublime Text), open the reinsurance-network folder. You should see the file layout in the explorer.

Updating the project configuration file

The metadata (name, version, description etc) for the business network definition is stored in the package.json file. Edit this file to change the name to ‘reinsurance-network’, the description to “Reinsurance Claims Network” and modify the prepublish script to change the name of the business network archive to ‘reinsurance-network.bna’.

Image for post
Image for post

Defining the reinsurance claims Domain Model

Open the file models/sample.cto and inspect the contents. This is the domain model for the business network definition. It defines the structure (schema) for the assets, transaction and participants in the business network.

We are going to replace the entire contents of the file ‘sample.cto’ with the simplistic reinsurance claims model to track the interactions between cedent and reinsurance on the blockchain:

The domain model defines two assets (Contrat, AvisSinistre) and two participants (“Cedante”, “Reassureur”) and a two transactions (“DeclarerSinistre”, “SouscrireContrat”) that is used to claims a sinister.

Finally rename the file ‘sample.cto’ to ‘reinsurance.cto

Image for post
Image for post
Reinsurance Composer model

Write Transaction Processor Functions (Claiming)

Now that the reinsurance domain model has been defined, we can write the business logic for the business network definition. Written in javascript, these functions are automatically executed when a transaction is submitted for processing.

Open the file lib/sample.js. If a JavaScript function has the @transaction annotation, it will be automatically invoked when a transaction of the type defined by the @param annotation is submitted.

Now replace the contents of sample.js with the function below :

Image for post
Image for post

This onDeclarationSinistre function simply add the claim amount to the cedent, and substract it from the reinsurer based on an incoming claim transaction. It then persists the modified asset and participants back into the registry.

Save your changes to lib/reinsurance.js

Generate the Business Network Archive

We can now generate a Business Network Archive (BNA) file for our reinsurance business network definition. Go back to the terminal and type:

> cd reinsurance-network
> npm install

You should see the following output:

> reinsurance-network@0.0.1 prepublish /home/user/reinsurance-network> mkdirp ./dist && composer archive create --sourceType dir --sourceName . -a ./dist/reinsurance-network.bna
Creating Business Network Archive
Looking for package.json of Business Network Definition in /home/user/reinsurance-networkFound:
Description: Reinsurance Trading network
Name: reinsurance-network
Identifier: reinsurance-network@0.0.1
Written Business Network Definition Archive file to ./dist/reinsurance-network.bna
Command completed successfully.
Command succeeded

The command has created a file called reinsurance-network.bna in the dist folder.

Import into Playground and Test

In a browser, navigate to the online Bluemix Composer Playground and import the generated BNA file into the Playground application using the “Import/Replace” button.

Locate the dist/reinsurance-network.bna file under your “reinsurance-network” folder and upload it, then press the “Deploy” button.

Node : You can also run a local Playground and import the model and add other participants like bellow :

Image for post
Image for post

Testing the reinsurance Business Network definition

Creating one cedent company

Create one cedent participant (AGF) by clicking the “Cedante” registry and the Create New Participant button.

"$class": "",
"id": "id :AGF",
"name": "AGF",
"solde": "1000"

Creating one reinsurance company

Create one “Reassurance” participant (for example CCR, Scor, or Swiss Re) by clicking the Reassurance registry and the Create New Participant button.

"$class": "",
"id": "id :CCR",
"name": "CCR",
"solde": "1000"

Creating a claim

Create a new instance of a Claim by navigating to the “AvisSinistre” registry and then click the Create New Asset button.

"$class": "",
"id": "id :Sinistre1",
"name": "Sinistre Incendie",
"information": "Incendie immeuble 1930",
"montant": "40",
"sent": "false"

You should see the following content in the Playground

Image for post
Image for post

Transferring the claim from cedent to reinsurance compagny

Next, submit a “DeclarerSinistre” transaction by clicking the “Submit Transaction” button. This will send the claim from the cedent to the reinsurance :

"$class": "",
"avisSinistre": "",
"cedante": "",
"reassureur": ""

After processing, you should now see the transaction in the transaction registry:

Image for post
Image for post

As a result, the balance of the reinsurance and cedent should be updated in the Asset Registry like below :
Cedent balance : 1000 + 40 = 1040
Reinsurance balance : 1000–40 = 960

Image for post
Image for post

If you are locally runing the Hyperledger Fabric and an explorer tool, you could see the transaction status in real time like bellow:

Image for post
Image for post

In a coming article, we will generate a REST API to provide developers easier interaction with the blockchain :

Image for post
Image for post

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade
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