一. Concepts
HyperLedger is an umbrella project of open source blockchains and related tools , started in December 2015 by the Linux Foundation , to support the collaborative development of blockchain-based ledgers .
HyperLedgerFabric is a subproject based on OpenBlockChain denoted by IBM .
HyperLedger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability.
HyperLedger Fabric is designed to support pluggable implementations of different components , and accommodate the complexity and intricacies that exist across the economy ecosystem.
HyperLedger Fabric delivers a uniquely elastic and extensible architecture , distinguishing it from alternative blockchain solutions . Planning for the future of enterprise blockchain requires building on top of a fully-vetted , open source architecture ; HyperLedger Fabric is your starting point .
2. HelloWorld
1. Setup docker for mac
Reference : http://blog.csdn.net/jiangmengya1/article/details/79354256
2. Download HyperLedger :
# git clone https://github.com/hyperledger/fabric.git
3. Download docker images
Enter directory fabric/scripts :
# cd .../fabric/scripts/
Modify bootstrap script :
# chmod _x bootstrap-1.0.0.sh # sed -i '' 's/curl/#curl/g' bootstrap-1.0.0.sh
Download images :
# ./bootstrap-1.0.0.sh
Show the images downloaded :
# docker images
4. Download HyperLedger Samples :
git clone https://github.com/hyperledger/fabric-samples.git
5. Launch :
Enter directory fabric-samples/basic-network :
# cd fabric-samples/basic-network/
Launch container using docker-compose :
# docker-compose -f docker-compose.yml up -d
Check it :
# docker ps
We can see something like this :
6. Demo :
# Switch the environment to the MSP of the administrator user and enter the peer node container peer0.org1.example.com
docker exec -it -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer0 .org1.example.com bash
# create a channel
peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
# join the channel
peer channel join -b mychannel.block
# exit Peer node container peer0.org1.example.com
exit #Exit
peer node container peer0.org1.example.com, enter cli container to install chaincode and instantiate:
# Enter cli container
docker exec -it cli /bin/bash
# Give to Peer Node peer0.org1.example.com install
chaincode peer chaincode install -n mycc -v v0 -p github.com/chaincode_example02
# Instantiate chaincode
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -v v0 -c '{"Args":["init","a","100","b","200"] }'
# Query initial value
# Display results respectively: Query Result 100 and Query Result 200
peer chaincode query -C mychannel -n mycc -v v0 -c '{"Args":["query","a"]}'
peer chaincode query -C mychannel -n mycc -v v0 -c '{"Args":["query","b"]}'
# transfer 10 coins from a to b
# show result:
peer chaincode invoke -C mychannel -n mycc -v v0 -c '{"Args":["invoke","a","b","10"]}'
# Query result value
# Display the results separately:Query Result 90 和 Query Result 210
peer chaincode query -C mychannel -n mycc -v v0 -c '{"Args":["query","a"]}'
peer chaincode query -C mychannel -n mycc -v v0 -c '{"Args":["query","b"]}'
7. Close :
Enter directory fabric-samples/basic-network :
# cd fabric-samples/basic-network/
Close Containers using docker-compose :
# docker-compose down
Check it :
# docker ps