Blockchain Application With Two Organizations

In this tutorial, we’re going to continue the previous one by adding a second organization and its peers into the channel. Then deploy the sample application to the peers of the second organization and upgrade the chaincode.

Note

It’s necessary to complete the Deploy First Blockchain Application before starting this tutorial.

Prerequisites

  • Go 1.12 and higher

  • Git

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

  • Docker Compose

1. Prepare New Organization

1.1 Create New Organization

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

Note

For the rest of this guide, the name first organization will reference the organization used in Deploy First Blockchain Application tutorial and the name second organization will reference the organization created in this step.

1.2 Issue Additional User Certificate

  • Make sure the second organization is selected.

  • 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.

2. Create Peers

  • Make sure the second organization is selected.

  • 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. Add New Organization To Channel

3.1 Invite New Organization To Channel

3.1 Accept Invitation To Channel

  • Make sure the second organization is selected.

  • Open the invite e-mail you just received and follow this guide to accept the invite.

3.2 Join Peers to Channel

  • Make sure the second organization is selected.

  • Join peers app-peer1 and app-peer2 to the app-channel.

4. Deploy Sample Chaincode

4.1 Install Sample Chaincode

  • Make sure the second organization is selected.

  • 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.

5. Run Sample Application

5.1 Download Channel SDK Config

Make those steps for both first and second organizations. You should have two sdk_config.yaml files one for each organization.

  • Navigate to the detail of app-channel.

  • Click Download SDK button in the information section.

  • Select appuser from the user list 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 for first organization to the config/org1 subdirectory of the path where you cloned the fabric-sdk-server-go in step 5.2 if the file already doesn’t exist from the previous tutorial.

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

  • Copy the private key file for the first organization from the previous tutorial to the keystore subdirectory of the path where you cloned the fabric-sdk-server-go in step 5.2 if the file already doesn’t exist from the previous tutorial.

  • Copy the private key file obtained in step 1.2 to 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 5.2.

  • Run Docker Compose

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

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

      make.bat example-two
      

6. Test Sample Application

The sample application runs in two instances. Both SDK server and front-End applications run in the context of each organization separately.

Front-end ports for organizations:

  • First organization: 8091

  • Second organization: 8092

6.1 Read Existing Data From Blockchain

We are going to use the context of the second organization in this step.

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

Click the Get button. This should list the data from the ledger. All data from the previous tutorial should be displayed.

6.2 Put Data Into Blockchain

We are going to use the context of the second organization in this step.

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

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

6.3 Read Data From Blockchain

We are going to use the context of the first organization in this step.

Open the web browser on http://localhost:8091/get.

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

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-two-down
      
    • If you’re using Windows run the following command.

      make.bat example-two-down