Normally chaincodes are started and maintained by peer. However in “dev mode", chaincode is built and started by the user. This mode is useful during chaincode development phase for rapid code/build/run/debug cycle turnaround.
We start "dev mode" by leveraging pre-generated orderer and channel artifacts for a sample dev network. As such, the user can immediately jump into the process of compiling chaincode and driving calls.
  docker-compose upThe above starts the network with the SingleSampleMSPSolo orderer profile and
launches the peer in "dev mode". It also launches two additional containers -
one for the chaincode environment and a CLI to interact with the chaincode. The
commands for create and join channel are embedded in the CLI container, so we
can jump immediately to the chaincode calls.
Get into bash shell in the chaincode container
docker exec -it chaincode bashCompile your chaincode
cd go-example
go build -o go-example-1Run the chaincode:
CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:v1 ./go-example-1Install dependencies via npm
cd js-example
npm installRun the chaincode:
CORE_CHAINCODE_ID_NAME=mycc:v1 node js-example-1.js --peer.address peer:7052
CORE_CHAINCODE_ID_NAME=mycc:v1 node measurements-registry.js --peer.address peer:7052In both examples you will see some 'Ready' text on last line
The chaincode is started with peer and chaincode logs indicating successful registration with the peer.
Note that at this stage the chaincode is not associated with any channel. This is done in subsequent steps
using the instantiate command.
Even though you are in --peer-chaincodedev mode, you still have to install the
chaincode so the life-cycle system chaincode can go through its checks normally.
This requirement may be removed in future when in --peer-chaincodedev mode.
We'll leverage the CLI container to drive these calls.
Get into bash shell in the chaincode container
docker exec -it cli bashpeer chaincode install -p chaincodedev/chaincode/go-example -n mycc -v v1
peer chaincode instantiate -n mycc -v v1 -c '{"Args":["init","a","100","b","200"]}' -C mycpeer chaincode install --lang node --name mycc --path /opt/gopath/src/chaincodedev/chaincode/js-example --version v1
peer chaincode instantiate --lang node -n mycc -v v1 -c '{"Args":["init","a","100","b","200"]}' -C myc
peer chaincode install --lang node --name mycc --path /opt/gopath/src/chaincodedev/chaincode/measurements-registry --version v1
peer chaincode instantiate --lang node -n mycc -v v1 -c '{"Args":["init"]}' -C mycLets run some functions on the chaincode/contract now.
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["registerMeasurement","ref123", "100", "timestamp"]}' -C mycFinally, query a. We should see a value of 90.
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
peer chaincode query -n mycc -c '{"Args":["queryMeasurementsByReference","ref123"]}' -C mycIf you want to try a contract again after code changes or reset the chain, maybe a bump in version number is needed
docker-compose down
docker-compose upKeep and eye on the contract version -v param in the commands. Get into bash shell in the chaincode container
docker exec -it cli bashpeer chaincode package -S --lang node -p /opt/gopath/src/chaincodedev/chaincode/measurements-registry -v v1 -n measurements-registry measurements-registry.cds