Deploy First Blockchain Application

This is a step-by-step guide on how to deploy your first blockchain application on top of the Hyperledger Fabric blockchain framework using KompiTech Blockchain Platform. You will first create your infrastructure including peers, orderers and a channel. As a next step chaincode and example application setup will follow.

Note

This example assumes that no resources have been created yet.

Prerequisites

  • Go 1.12 and higher

  • Git

  • Make (if you’re using Linux or macOS)

  • Docker Compose

1. Prepare Organization

This example requires a newly created organization in the KompiTech Blockchain Platform with one additional user certificate in Identity.

1.1 Create Account and Organization

  • If you’re new user: You just log-in, create an account and the first organization will be created automatically.

  • If you already have an organization created: Please make sure there are no peers, orderers, and channels present. You can also create an additional organization.

Note

An organization in the KompiTech Blockchain Platform corresponds with the organization in Hyperledger Fabric. For each organization created in the Platform, the default root certificate authority (CA) is created. This CA is by default added to the organization’s CA certificate list when creating peers, orderers, and channels.

1.2 Issue Additional User Certificate

  • Issue user certificate with the name appuser. You can choose the name you want but for the rest of this guide, an appuser will be a reference to this particular user certificate. Don’t check the IDaaS option.

Warning

After the user certificate has been issued it’s private key is shown only once. Please save it to a safe location because it cannot be retrieved afterward.

Note

For each organization created in the KompiTech Blockchain Platform, the default admin user certificate is created. The admin user certificate is automatically added in the list of the organization’s admin certificates when creating peers, orderers, and channels.

This user certificate is used for Platform’s administration purposes, it’s key is securely stored in internal encrypted Identity as a Service (IDaaS) and it cannot be retrieved. This means you cannot for security reasons use this default admin identity as a user of the external application using Platform’s blockchain network as a backend.

For external applications, there’s an option to issue a user certificate with any other name than admin which can be used as a user for the Platform’s blockchain network.

2. Create Blockchain Infrastructure

In this sample use-case, we’ll assume only one organization is participating in the blockchain network. It has one orderer, two peers and there is one channel.

2.1 Create Orderer

  • Create orderer with name app-orderer and add the appuser to additional admin certificates

  • Wait until the state for the orderer is RUNNING

2.2 Create Peers

  • Create two peers with names app-peer1 app-peer2 and add the appuser to additional admin certificates for both of them.

  • Wait until the state for both peers is RUNNING

3. Create Channel

  • Create a channel with name app-channel, add the appuser to additional admin certificates and add both peers created in step 2.2 with all the options selected.

  • Wait until the state for the channel is READY

4. Deploy Sample Chaincode

For every organization, KompiTech Blockchain Platform automatically adds one example chaincode for testing purposes. This chaincode can simply store, read, list and delete strings. Its source code can be found here.

4.1 Install Sample Chaincode

  • Install chaincode named example to both peers app-peer1 and app-peer2.

  • Verify the example chaincode is not in ERROR state by checking it in the detail page of each peer.

4.1 Instantiate Sample Chaincode

  • Instantiate chaincode named example to the channel app-channel using either of peers. In advanced fields select Endorsement policy Signed by any member and select the MSPID of your organization (there should be the only one available) in the MSPID input. Leave all other fields blank.

  • Verify the example chaincode is not in ERROR state by checking it in the detail page of the app-channel.

5. Run Sample Application

5.1 Download Channel SDK Config

  • Navigate to the detail of the app-channel.

  • Click the Download SDK button in the information section.

  • Select the appuser from the user certificates and click the Download button.

  • Save the file anywhere on your local file system and name it sdk_config.yaml.

5.2 Download Sample Application

5.3 Add SDK Configuration to Sample Application

  • Copy the downloaded sdk_config.yaml file to the config/org1 subdirectory of the path where you cloned the fabric-sdk-server-go in step 5.2.

  • Copy the private key file obtained in step 1.2 in the keystore subdirectory of the path where you cloned the fabric-sdk-server-go in step 5.2.

5.4 Run Sample Application

Note

These steps need to be executed using the command line.

  • Navigate to the path where you cloned the fabric-sdk-server-go in step 6.2.

  • Run the Docker Compose

    • If you’re using Linux or macOS Run the following command.

      make example-one
      
    • If you’re using Windows run the following command.

      make.bat example-one
      

6. Test Sample Application

The sample application consists of two components:

  • HTTP server which does querying the Fabric network.

  • Front-End application.

6.1 Put Data Into Blockchain

Open the web browser on http://localhost:8090/send. The form for creating data in the blockchain will be shown. User and Channel name fields will be selected automatically from config.

Put some data in the Create contract form and click the Create button. This should create the data in the ledger.

6.2 Read Data From Blockchain

Open the web browser on http://localhost:8090/get. The form for listing data in the blockchain will be shown. User and Channel name fields will be selected automatically from config.

Click the Get button. This should list the data from the ledger. Data from the previous step should be displayed.

7. Tear Down the Application

You can continue with adding and reading data. After you are finished with testing tear down the Docker Compose.

Note

Those steps need to be executed using the command line.

  • Navigate to the path where you cloned the fabric-sdk-server-go in step 6.2 into subdirectory examples/one-org.

  • Run the Docker Compose

    • If you’re using Linux or macOS Run the following command.

      make example-one-down
      
    • If you’re using Windows run the following command.

      make.bat example-one-down