github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/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 All commands are executed from the ``fabric`` folder. 15 16 Start the orderer 17 ----------------- 18 19 :: 20 21 ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo orderer 22 23 The above starts the orderer in the local environment the orderer 24 configuration as defined in ``sampleconfig/orderer.yaml`` with the 25 genesisprofile directive overridden to use the SampleDevModeSolo profile 26 for bootstrapping the network. 27 28 Start the peer in dev mode 29 -------------------------- 30 31 :: 32 33 peer node start --peer-chaincodedev=true 34 35 The above command starts the peer using the default ``sampleconfig/msp`` 36 MSP. The ``--peer-chaincodedev=true`` puts it in “dev” mode. 37 38 Create channels ch1 and ch2 39 --------------------------- 40 41 Generate the transactions for creating the channels using ``configtxgen`` tool. 42 43 :: 44 configtxgen -channelID ch1 -outputCreateChannelTx ch1.tx -profile SampleSingleMSPChannel 45 configtxgen -channelID ch2 -outputCreateChannelTx ch2.tx -profile SampleSingleMSPChannel 46 47 where SampleSingleMSPChannel is a channel profile in ``sampleconfig/configtx.yaml`` 48 49 :: 50 51 peer channel create -o 127.0.0.1:7050 -c ch1 -f ch1.tx 52 peer channel create -o 127.0.0.1:7050 -c ch2 -f ch2.tx 53 54 Above assumes orderer is reachable on ``127.0.0.1:7050``. The orderer 55 now is tracking channels ch1 and ch2 for the default configuration. 56 57 :: 58 59 peer channel join -b ch1.block 60 peer channel join -b ch2.block 61 62 The peer has now joined channels cha1 and ch2. 63 64 Start the chaincode 65 ------------------- 66 67 :: 68 69 cd examples/chaincode/go/chaincode_example02 70 go build 71 CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02 72 73 The chaincode is started with peer and chaincode logs indicating successful registration with the peer. 74 Note that at this stage the chaincode is not associated with any channel. This is done in subsequent steps 75 using the ``instantiate`` command. 76 77 Use the chaincode 78 ----------------- 79 80 Even though you are in ``--peer-chaincodedev`` mode, you still have to install the chaincode so the life-cycle system 81 chaincode can go through its checks normally. This requirement may be removed in future when in ``--peer-chaincodedev`` 82 mode. 83 84 :: 85 86 peer chaincode install -n mycc -v 0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 87 88 Once installed, the chaincode is ready to be instantiated. 89 90 :: 91 92 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch1 93 94 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch2 95 96 The above instantiates the chaincode with the two channels. With default 97 settings it might take a few seconds for the transactions to be 98 committed. 99 100 :: 101 102 peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch1 103 peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch2 104 105 The above invoke the chaincode over the two channels. 106 107 Finally, query the chaincode on the two channels. 108 109 :: 110 111 peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch1 112 peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch2 113 114 .. Licensed under Creative Commons Attribution 4.0 International License 115 https://creativecommons.org/licenses/by/4.0/ 116