โ–ถ๏ธChaincode Execution

  1. This chaincode fabcar, has to be initialized before executing other transactions.

source ./scripts/setPeerConnectionParam.sh 1 2

source ./scripts/setOrgPeerContext.sh 1

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n fabcar $PEER_CONN_PARAMS --isInit -c '{"function":"initLedger","Args":[]}'
  1. Let's create a new car

source ./scripts/setOrgPeerContext.sh 1

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C $CHANNEL_NAME -n fabcar $PEER_CONN_PARAMS -c '{"function":"CreateCar","Args":["CAR11","Tata","Safari", "Red", "Ron"]}'
  1. Query the Status of the state after init.

peer chaincode query -C $CHANNEL_NAME -n fabcar -c '{"Args":["queryAllCars"]}'
  1. Change the ownership of CAR11 to John:

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C $CHANNEL_NAME -n fabcar $PEER_CONN_PARAMS -c '{"function":"changeCarOwner","Args":["CAR11","John"]}'
  1. As Org2 query to check the status as ownership of CAR11

source ./scripts/setOrgPeerContext.sh 2

peer chaincode query -C $CHANNEL_NAME -n fabcar -c '{"Args":["queryCar","CAR11"]}'

Play around with it.

Last updated