Chaincodes

Chaincode is a program, written in Go, node.js, or Java that implements a prescribed interface. Chaincode runs in a secured Docker container isolated from the endorsing peer process. Chaincode initializes and manages ledger state through transactions submitted by applications.

A chaincode typically handles business logic agreed to by members of the network, so it may be considered as a “smart contract”. The state created by a chaincode is scoped exclusively to that chaincode and can’t be accessed directly by another chaincode. However, within the same network, given the appropriate permission, a chaincode may invoke another chaincode to access its state.

Note

Before manipulating any chaincodes make sure you’re logged in, have your organization selected properly and Hyperledger Fabric is selected from the Blockchain menu.

Note

Currently, the only chaincode language supported by KompiTech Blockchain Platform is Go.

Package Chaincode

  1. Create a vendor directory with dependencies in the path of chaincode source files.

  2. Create a gzipped TAR package of the directory containing source code of the chaincode. The main.go file and vendor directory have to be in the root of the package.

Upload Chaincode

  1. Navigate to Chaincodes option in the side menu.

  2. Click the + Chaincode button in the upper right corner.

  3. Fill in the form with details and click the Upload your chaincode button.

Fields description

  • Name - Chaincode name.

  • Version - Version of the chaincode.

  • Path - Path to the chaincode source files relative to the GOPATH environment variable.

  • Description - Optional description of the chaincode.

  • Chaincode - Input field for uploading chaincode TAR file.

Install Chaincode

The install operation packages a chaincode’s source code into a prescribed format called a ChaincodeDeploymentSpec (or CDS) and copies it on a filesystem of a peer node that will run the chaincode.

There are 3 possible ways to install chaincode on peers and are described below.

Install from the chaincodes section

  1. Navigate to Chaincodes option in the side menu.

  2. Click on the Install button of the chaincode you want to install. The chaincode version dialog will show up. Choose one and click the Continue button.

  3. Select peers you want to install the chaincode on and click the``Continue`` button.

  4. Click the Install button.

Install from the peer list

  1. Navigate to Resources option in the side menu.

  2. Make sure the Peers tab is selected.

  3. Click on the Install chaincode button in the upper right corner. The select peers dialog will show up.

  4. Select peers you want to install the chaincode on and click the Continue button.

  5. Choose one chaincode and click the Continue button.

  6. Click the Install button on the summary page.

Install from the peer detail

  1. Navigate to Resources option in the side menu.

  2. Make sure the Peers tab is selected.

  3. Open the detail of the peer you want to install chaincode on.

  4. Click the +Install button above the installed chaincodes list. The chaincode select dialog will show up.

  5. Select chaincodes you want to install.

  6. Click the Install button.

Instantiate Chaincode

Instantiate from the chaincodes section

  1. Navigate to Chaincodes option in the side menu.

  2. Click on the Instantiate button of the chaincode you want to instantiate. The select channel dialog will show up.

  3. Select a channel you want to instantiate the chaincode on. The chaincode version dialog will show up. Choose one and click the Continue button.

  4. The select channel dialog will show up. Choose the channel you want to instantiate and click the Continue button.

  5. The select peer dialog will show up. Click on the peer you want to use to send the instantiate transaction to. The advanced arguments dialog will show up.

  6. Fill the advanced argument’s form.

  7. Click the Instantiate button.

Instantiate from the channel detail

  1. Navigate to Channels option in the side menu.

  2. Open the detail of the channel you want to instantiate chaincode in.

  3. Click on the Instantiate button above the Instantiated chaincodes list. The select chaincode dialog will show up.

  4. Select the chaincode you want to instantiate. The select peer dialog will show up.

  5. Click on the peer you want to use for sending the instantiate transaction to. The advanced arguments dialog will show up.

  6. Fill the advanced arguments form.

  7. Click the Instantiate button.

Advanced arguments fields

  • Endorsement policy - Every chaincode has an endorsement policy that specifies the set of peers on a channel that must execute chaincode and endorse the execution results in order for the transaction to be considered valid.

  • MSPIDs - MSPIDs of organizations that will participate in the endorsement policy.

  • Private data collections - Private data definition.

  • Arguments - Initial arguments to pass to the init method of the chaincode in the JSON format.

  • Upgrade - If the chaincode is already instantiated and you want to upgrade to the new version set this field to true.

Upgrade Chaincode

Upgrading the chaincode is done the same way as the instantiating is done. The only requirement is that the lower version of the chaincode you’re upgrading is already instantiated in the channel. Also, make sure the Upgrade field is selected in the advanced arguments.

Delete Chaincode

  1. Navigate to Chaincodes option in the side menu.

  2. Click on the Delete button of the chaincode you want to delete.