Create Your Application

Writing a Simple “Hello World” Chaincode

Catalyst Blockchain Manager runs chaincodes as external services, meaning that this must be considered during deployment.

A detailed guide on how to write external chaincode can be found in the official Hyperledger Fabric documentation

Here, we will be using an already created simple “Hello World” chaincode example written in Go to show specific details of how to run smart contracts in Catalyst Blockchain Manager. The source code of this chaincode can be found following the link

The key part of this example chaincode is the function where its server starts:

func main() {
  ccid := os.Getenv("CHAINCODE_ID")
  address := os.Getenv("CHAINCODE_ADDRESS")

  server := &shim.ChaincodeServer{
     CCID: ccid,
     Address: address,
     CC: &HelloWorld{},
     TLSProps: shim.TLSProperties{
     Disabled: true,
     },
  }

  if err := server.Start(); err != nil {
  fmt.Printf("Error starting HelloWorld chaincode: %s", err)
  }
}

To run chaincode in Catalyst Blockchain Manager, you need to set CCID and Address fields of shim.ChaincodeServer as environment variables CHAINCODE_ID and CHAINCODE_ADDRESS , respectively.

These two environment variables will be passed during the creation of the chaincode external service, CHAINCODE_ID matches chaincode package id after its installation on a peer and CHAINCODE_ADDRESS is the listen address of a chaincode server that was used to build the chaincode server endpoint accessible from a peer in connection.json.

Communication with Catalyst Blockchain Manager

There are two ways to communicate with Catalyst Blockchain Manager: Hyperledger Fabric SDK and Catalyst Blockchain Manager API.

Hyperledger Fabric SDK

There are many different Hyperledger Fabric resources and guides on configuring the SDK for interaction with Hyperledger Fabric, and these can be utilized as well.

To complete SDK integration with Catalyst Blockchain Manager:

  1. Register a client signing identity and TLS identity for the business application on behalf of your Catalyst Blockchain Manager user.

  2. Enroll the registered identities through SDK CA client from your business application or Hyperledger Fabric CA Client in CLI.

The detailed guide on how to enroll an identity on the client side can be found here

SDK method allows you to fully integrate with Catalyst Blockchain Manager and interact with all network components. However, this method is complicated. Instead of using Hyperledger Fabric SDK, you can use

Catalyst Blockchain Manager API

For communication between your business application and a chaincode, Catalyst Blockchain Manager provides you with an API to invoke, query deployed chaincodes, and subscribe for chaincode’s events.

Endpoints and required parameters are listed here.