超级账本(一) HyperLedger Fabric 环境搭建


一. 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 .


二. 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 :

# 切换环境到管理员用户的MSP,进入Peer节点容器peer0.org1.example.com
docker exec -it -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp" peer0.org1.example.com bash

# 创建通道
peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx

# 加入通道
peer channel join -b mychannel.block

# 退出Peer节点容器peer0.org1.example.com
exit

#退出Peer节点容器peer0.org1.example.com,进入cli容器安装链码和实例化:
# 进入cli容器
docker exec -it cli /bin/bash

# 给Peer节点peer0.org1.example.com安装链码
peer chaincode install -n mycc -v v0 -p github.com/chaincode_example02

# 实例化链码
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -v v0 -c '{"Args":["init","a","100","b","200"]}'

# 查询初始值
# 分别显示结果 : Query Result 100 和 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"]}'

# 从 a 转移 10 币到 b
# 显示结果 : 
peer chaincode invoke -C mychannel -n mycc -v v0 -c '{"Args":["invoke","a","b","10"]}'

# 查询结果值
# 分别显示结果 : 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 




猜你喜欢

转载自blog.csdn.net/jiangmengya1/article/details/79376337