🚚Chaincode Deployment

We are going to deploy FabCar chaincode on Test Network. Till now we have created a channel and our peers have joined the channel.

  1. We need to write a script to configure chaincode environment variables. Create a new script file inside fabric-samples/test-network/scripts and name it setFabCarGolangContext.sh

export CC_RUNTIME_LANGUAGE=golang
export CC_SRC_PATH="../chaincode/fabcar/go/"
export VERSION=1

echo Vendoring Go dependencies ...
pushd ../chaincode/fabcar/go
export GO111MODULE=on go mod vendor
popd
echo Finished vendoring Go dependencies
  1. Update the environment variable to configure the use of GoLang Chaincode.

source ./scripts/setFabCarGolangContext.sh
export FABRIC_CFG_PATH=$PWD/../config/
export FABRIC_CFG_PATH=${PWD}/configtx
export CHANNEL_NAME=mychannel
export PATH=${PWD}/../bin:${PWD}:$PATH
  1. Package the chaincode: Chaincode needs to be packaged in a tar file before it can be installed on your peers. You can package a chaincode using the Fabric peer binaries, the Node Fabric SDK, or a third-party tool such as GNU tar.

source ./scripts/setOrgPeerContext.sh 1
peer lifecycle chaincode package fabcar.tar.gz --path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} --label fabcar_${VERSION}

Check if the package is created: ‘fabcar.tar.gz’ file should be seen.

  1. Install the Chaincode: You need to install the chaincode package on every peer that will execute and endorse transactions. You need to complete this step using your Peer Administrator, whether using the CLI or an SDK.

    A successful install command will return a chaincode package identifier, which is the package label combined with a hash of the package. This package identifier associates a chaincode package installed on your peers with a chaincode definition approved by your organization.

    1. Install the chaincode on the peer of Org1

  1. Install the chaincode on peer of Org2

  1. The Query for Installed package

  1. Set the PACKAGE_ID value

Create a new script file inside the scripts folder named: setPackageID.sh and write below code inside it.

Now run the script by below cmd.

  1. Approval Process: The chaincode is governed by a chaincode definition. When channel members approve a chaincode definition, the approval acts as a vote by an organization on the chaincode parameters it accepts. These approved organization definitions allow channel members to agree on a chaincode before it can be used on a channel.

    1. Approve the Chaincode as Org1

  1. Check for committedness as Org1

  1. Check for committedness as Org2

  1. Approve the Chaincode as Org2

  1. Check for committedness as Org2

  1. Check for committedness as Org1

  1. Set the peer address for identifying the endorsing peers

Create a new script in the scripts the folder named: setPeerConnectionParam.sh

Now run the script.

  1. Commit the chaincode definition to Channel

  1. Check docker status

  1. Query chaincode commit as Org2

  1. Query chaincode commit as Org1

Last updated

Was this helpful?