github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/docs/source/peer-chaincode-devmode.rst (about) 1 Using dev mode 2 ============== 3 4 Normally chaincodes are started and maintained by peer. However in “dev” 5 mode, chaincode is built and started by the user. This mode is useful 6 during chaincode development phase for rapid code/build/run/debug cycle 7 turnaround. 8 9 To keep this a realistic “dev” environment, we are going to keep it “out 10 of the box” - with one exception: we create two channels instead of 11 using the default ``testchainid`` channel to show how the single running 12 instance can be accessed from multiple channels. 13 14 - Note: Make sure peer is not using TLS when running in dev mode. 15 16 All commands are executed from the ``fabric`` folder. 17 18 Start the orderer 19 ----------------- 20 21 :: 22 23 ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo orderer 24 25 The above starts the orderer in the local environment the orderer 26 configuration as defined in ``sampleconfig/orderer.yaml`` with the 27 genesisprofile directive overridden to use the SampleDevModeSolo profile 28 for bootstrapping the network. 29 30 Start the peer in dev mode 31 -------------------------- 32 33 :: 34 35 peer node start --peer-chaincodedev=true 36 37 The above command starts the peer using the default ``sampleconfig/msp`` 38 MSP. The ``--peer-chaincodedev=true`` puts it in “dev” mode. 39 40 Create channels ch1 and ch2 41 --------------------------- 42 43 Generate the transactions for creating the channels using ``configtxgen`` tool. 44 45 :: 46 configtxgen -channelID ch1 -outputCreateChannelTx ch1.tx -profile SampleSingleMSPChannel 47 configtxgen -channelID ch2 -outputCreateChannelTx ch2.tx -profile SampleSingleMSPChannel 48 49 where SampleSingleMSPChannel is a channel profile in ``sampleconfig/configtx.yaml`` 50 51 :: 52 53 peer channel create -o 127.0.0.1:7050 -c ch1 -f ch1.tx 54 peer channel create -o 127.0.0.1:7050 -c ch2 -f ch2.tx 55 56 Above assumes orderer is reachable on ``127.0.0.1:7050``. The orderer 57 now is tracking channels ch1 and ch2 for the default configuration. 58 59 :: 60 61 peer channel join -b ch1.block 62 peer channel join -b ch2.block 63 64 The peer has now joined channels cha1 and ch2. 65 66 Start the chaincode 67 ------------------- 68 69 :: 70 71 cd examples/chaincode/go/chaincode_example02 72 go build 73 CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02 74 75 The chaincode is started with peer and chaincode logs indicating successful registration with the peer. 76 Note that at this stage the chaincode is not associated with any channel. This is done in subsequent steps 77 using the ``instantiate`` command. 78 79 Use the chaincode 80 ----------------- 81 82 Even though you are in ``--peer-chaincodedev`` mode, you still have to install the chaincode so the life-cycle system 83 chaincode can go through its checks normally. This requirement may be removed in future when in ``--peer-chaincodedev`` 84 mode. 85 86 :: 87 88 peer chaincode install -n mycc -v 0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 89 90 Once installed, the chaincode is ready to be instantiated. 91 92 :: 93 94 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch1 95 96 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch2 97 98 The above instantiates the chaincode with the two channels. With default 99 settings it might take a few seconds for the transactions to be 100 committed. 101 102 :: 103 104 peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch1 105 peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch2 106 107 The above invoke the chaincode over the two channels. 108 109 Finally, query the chaincode on the two channels. 110 111 :: 112 113 peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch1 114 peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch2 115 116 .. Licensed under Creative Commons Attribution 4.0 International License 117 https://creativecommons.org/licenses/by/4.0/ 118