github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/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  Start the orderer
    15  -----------------
    16  
    17  ::
    18  
    19      orderer
    20  
    21  The above starts the orderer in the local environment using default
    22  orderer configuration as defined in ``sampleconfig/orderer.yaml``.
    23  
    24  Start the peer in dev mode
    25  --------------------------
    26  
    27  ::
    28  
    29      peer node start --peer-defaultchain=false --peer-chaincodedev=true
    30  
    31  The above command starts the peer using the default ``sampleconfig/msp``
    32  MSP. The ``--peer-chaincodedev=true`` puts it in “dev” mode.
    33  
    34  Create channels ch1 and ch2
    35  ---------------------------
    36  
    37  ::
    38  
    39      peer channel create -o 127.0.0.1:7050 -c ch1
    40      peer channel create -o 127.0.0.1:7050 -c ch2
    41  
    42  Above assumes orderer is reachable on ``127.0.0.1:7050``. The orderer
    43  now is tracking channels ch1 and ch2 for the default configuration.
    44  
    45  ::
    46  
    47      peer channel join -b ch1.block
    48      peer channel join -b ch2.block
    49  
    50  The peer has now joined channels cha1 and ch2.
    51  
    52  Start the chaincode
    53  -------------------
    54  
    55  ::
    56  
    57      cd examples/chaincode/go/chaincode_example02
    58      go build
    59      CORE_CHAINCODE_LOGLEVEL=debug CORE_PEER_ADDRESS=127.0.0.1:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
    60  
    61  The chaincode is started with peer and chaincode logs showing it got
    62  registered successfully with the peer.
    63  
    64  Use the chaincode
    65  -----------------
    66  
    67  ::
    68  
    69      peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch1
    70  
    71      peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -o 127.0.0.1:7050 -C ch2
    72  
    73  The above instantiates the chaincode with the two channels. With default
    74  settings it might take a few seconds for the transactions to be
    75  committed.
    76  
    77  ::
    78  
    79      peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch1
    80      peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -o 127.0.0.1:7050 -C ch2
    81  
    82  The above invoke the chaincode over the two channels.
    83  
    84  ::
    85  
    86      peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch1
    87      peer chaincode query -n mycc -c '{"Args":["query","a"]}' -o 127.0.0.1:7050 -C ch2