• +1 (901) 701-TECH
  • St.Louis, US

Run Chaincode Locally

Chaincode is a program, written in Go, and eventually in other programming languages such as 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.

  • Install Fabric Samples
  • Get fabricsamples repository in your local machine by typing this command
  • git clone
  • Enter into chaincode-docker-devmode directory of the fabric-samples
  • cd chaincode-docker-devmode
  • Install Binaries and Docker Images
  • Execute the following command from within the directory into which you will extract the platform-specific binaries
  • curl -sSL | bash -s 1.0.6
  • Start the network in one terminal
  • docker-compose -f docker-compose-simple.yaml up
  • Open Another terminal enter in to chaincode conatiner and run any chaincode, Here we are running chaincode_example02 present in chaincode directory.
  • docker exec -it chaincode bash
  • You should see the following
  • root@d2629980e76b:/opt/gopath/src/chaincode#
  • Now, compile your chaincode
  • cd chaincode_example02 go build
  • Now run the chaincode
  • CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
  • Here u will see all transactions done by this chaincode.
  • Open Another Terminal and enter into cli and operate chaincode
  • docker exec -it cli bash peer chaincode install -p chaincodedev/chaincode/chaincode_example02 -n mycc -v 0 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
  • Now issue an invoke to move 10 from a to b.
  • peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
  • Finally, query a. We should see a value of 90.
  • peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc


© 2016 KE TECHIES. All rights reserved | Design by W3layouts