You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

After cloning Fabric, you can can test fabric binaries using a sample configuration. Using the binaries and sample configuration makes it simple and quick to iteratively make code changes, rebuild fabric, and test your changes from an end-to-end consumer perspective.


Terminal prep

Add fabric /build/bin to your PATH so that you can easily execute the binaries.
Set FABRIC_CFG_PATH to fabric /sampleconfig directory, which contains sample orderer.yaml, peer.yaml, configtx.yaml, and msp for a SampleOrg.

Open three terminal windows, one each for orderer, peer, and CLI. cd to /fabric directory in each terminal.


Build fabric

Build fabric binaries in any terminal:
   make orderer peer configtxgen

Build docker images in any terminal (we'll need baseos and ccenv docker images for chaincode):

   make docker-clean docker


orderer terminal

Create a system channel genesis block:

   configtxgen -profile SampleSingleMSPSolo -channelID test-system-channel-name -outputBlock sampleconfig/genesisblock

Start orderer, which by default will use /sampleconfig/genesisblock:

   orderer


peer terminal

Start peer (with debug logging enabled for all but the chattiest packages):

   FABRIC_LOGGING_SPEC=debug:cauthdsl,policies,msp,grpc,peer.gossip.mcs,gossip,leveldbhelper=info peer node start


CLI terminal

Create a channel genesis block from the configtx.yaml profile:

   configtxgen -channelID mychannel -outputCreateChannelTx mychannel.tx -profile SampleSingleMSPChannel

Create a channel on the orderer:

   peer channel create -c mychannel -o 127.0.0.1:7050 -f mychannel.tx

Join the peer to the channel (note, peer address in core.yaml is used)

   peer channel join -b mychannel.block

Package chaincode:

   peer lifecycle chaincode package marbles.tar.gz --path github.com/hyperledger/fabric/integration/chaincode/marbles/cmd --lang golang --label marbles_1

Install chaincode to peer:

   peer lifecycle chaincode install marbles.tar.gz

Set CC_PACKAGE_ID to the value returned by install step, e.g.:

   CC_PACKAGE_ID=marbles_1:1a17ae87243ad78f0203ca921b733c52adbf7ad2816340ea876ef1b5cc56c0db

Approve chaincode definition on channel for SampleOrg:

   peer lifecycle chaincode approveformyorg --channelID mychannel --name marbles --version 1 --package-id $CC_PACKAGE_ID --sequence 1

Commit chaincode definition to channel:

   peer lifecycle chaincode commit -o 127.0.0.1:7050 --channelID mychannel --name marbles --version 1 --sequence 1

Invoke chaincode to create a marble:

   peer chaincode invoke -o 127.0.0.1:7050 -C mychannel -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}' --waitForEvent

Transfer marble:

   peer chaincode invoke -o 127.0.0.1:7050 -C mychannel -n marbles -c '{"Args":["transferMarble","marble1","jerry"]}' --waitForEvent

Query marble:

   peer chaincode query -C mychannel -n marbles -c '{"Args":["readMarble","marble1"]}'


Cleanup data, chaincode containers and images

rm -r /var/hyperledger/

docker rm -f $(docker ps -aq)

docker rmi -f $(docker images -q --filter=reference='*dev*')


The CLI commands can be scripted or copy/pasted to expedite execution:

configtxgen -channelID mychannel -outputCreateChannelTx mychannel.tx -profile SampleSingleMSPChannel
peer channel create -c mychannel -o 127.0.0.1:7050 -f mychannel.tx
peer channel join -b mychannel.block
peer lifecycle chaincode package marbles.tar.gz --path github.com/hyperledger/fabric/integration/chaincode/marbles/cmd --lang golang --label marbles_1
peer lifecycle chaincode install marbles.tar.gz
CC_PACKAGE_ID=marbles_1:1a17ae87243ad78f0203ca921b733c52adbf7ad2816340ea876ef1b5cc56c0db
peer lifecycle chaincode approveformyorg --channelID mychannel --name marbles --version 1 --package-id $CC_PACKAGE_ID --sequence 1
peer lifecycle chaincode commit -o 127.0.0.1:7050 --channelID mychannel --name marbles --version 1 --sequence 1
peer chaincode invoke -o 127.0.0.1:7050 -C mychannel -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}' --waitForEvent
peer chaincode invoke -o 127.0.0.1:7050 -C mychannel -n marbles -c '{"Args":["transferMarble","marble1","jerry"]}' --waitForEvent
peer chaincode query -C mychannel -n marbles -c '{"Args":["readMarble","marble1"]}'


For legacy chaincode, replace the package/install/approve/commit chaincode with the following:

peer chaincode install -n marbles -p github.com/hyperledger/fabric/integration/chaincode/marbles/cmd -v 1
peer chaincode instantiate -C mychannel -n marbles -c '{"Args":["init"]}' -v 1 -o 127.0.0.1:7050



  • No labels