The first nine chapters analyze with you easily complete explosion hyperledger fabric - to build block chain network

table of Contents

1 Introduction

2 configuration environment super books

    2.1 Download fabric Source

    2.2 Unzip source

    2.3 download Docker image

        2.3.1 Add the startup script execute permissions

        Notes 2.3.2 Download statement

        2.3.3 Download Docker image

3 books deployment of super multi-node network

    3.1 download fabric-sample

    3.2 Starting container

4. Create channel

Chain installation and initialization code 5

6 chain code operation

    6.1 Queries

    6.2 Transfer


1 Introduction

        I think the best way to learn a new technology is hands-on, rather than theory. Based on this principle, I rarely addition to hands-hundred thousand forced hundred theories blog. Because I think the time is long past the text, and the power of words, but obviously cover video. Now, in addition to general shopping blog to solve practical problems, basically do not stay Gradually, the technology blog into the bathroom of the Internet has become a place we solve real needs.

        This section does not speak block chain theory, if you are holding the purpose of listening to stories come in, then I am sorry, I advise you to leave early.

        Today hyperledger fabric has come to version 2 of the era, but this figure is 2 personal mind, so this is still using version 1. This article will make it easy and free to set up the entire fabric, so you can rest assured. Come on, kids, brother to departure, and you line up the formation, ready to scream.

        Here affectionate reminder, best brother in accordance with the procedures and specified version, do not do what changes do nothing to challenge the challenge that. You have to really hurt bored there, want to practice your guts, you can try to kiss a beautiful opposite sex or the opposite sex bathroom armed with, I think that some of the more exciting, but also allow you a sense of accomplishment and conquest. Well, now here we go.


2 configuration environment super books

2.1 Download fabric Source

        Do not hear a source tremble, then the urine under the rain, will not let you compile.

wget https://github.com/hyperledger/fabric/archive/v1.0.0.tar.gz

2.2 Unzip source

tar -zxvf  fabric-1.0.0.tar.gz

2.3 download Docker image

2.3.1 Add the startup script execute permissions

cd fabric-1.0.0/scripts

chmod +x bootstrap-1.0.0.sh

Notes 2.3.2 Download statement

        If you are a mac operating system:

sed -i '' 's/curl/#curl/g' bootstrap-1.0.0.sh

        If you are a linux operating system:

sed -i 's/curl/#curl/g' bootstrap-1.0.0.sh

        If you are a window operating system:

& (*) (*) # * (_) # (_) # (_) (#_) # () _ R * (& T * ^ & * # ^ & (* # you just play

2.3.3 Download Docker image

./bootstrap-1.0.0.sh

image1.png

        Since then, the whole super minimizing environmental books was finished you easily burst. At this point, you can move your move stiff ass, put a P enliven the atmosphere of it.


3 books deployment of super multi-node network

3.1 download fabric-sample

        For simplicity, you still directly under the fabric samples provided by the deployment of multi-node network, right, first, the concept of a network first. Download the following address, choose according to your own operating system:

https://github.com/hyperledger/fabric/releases/tag/v1.1.0

        If you are a mac operating system directly under here, you're welcome big brother is so considerate.

https://github.com/hyperledger/fabric/releases/download/v1.1.0/hyperledger-fabric-darwin-amd64-1.1.0.tar.gz

3.2 Starting container

        启动容器需要 docker-compose,如果你是 mac,而且又安装了 docker,那么系统会自动为你安装好 docker-compose;如果你是 linux,可以参考哥的《九析带你玩转 docker-compose - 安装篇》安装 docker-compose。

cd fabric-samples-1.1.0/basic-network

docker-compose -f docker-compose.yml up -d

docker ps

image2.png


4. 创建通道

        其实我特别讨厌这些专业术语,我觉得现在 IT 界越来越不说人话。你可以把通道想成微信群,如果一些人想互相聊天,必须要同处于一个微信群才可以。记好了:通道 == 微信群。

        这里还需要介绍一个术语:MSP,你说这都是些什么玩意。你可以把 MSP 联想成一种身份。比如管理员身份、普通用户身份等等。

        好了,介绍完通道和 MSP 之后,你可以继续下面的操作了。

        首先以管理员 MSP 登录 Peer 节点,然后创建通道。你可以联想成管理员(MSP)登录微信(Peer)创建微信群。登录 peer 所在节点(因为 peer 节点已经 docker 化了,其实这里就是直接登录 docker 容器):

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

        创建完通道之后,直接退出 peer0 容器即可:

exit


5 安装和初始化链码

        安装和初始化链码的工作是在 cli 容器进行,所以要先进入 cli 容器:

docker exec -it cli /bin/bash

        安装链码:

peer chaincode install -n jiuxi -v v0 -p github.com/chaincode_example02/go

        实例化链码:

peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n jiuxi -v v0 -c '{"Args": ["init", "a", "100", "b", "200"]}'


6 链码操作

6.1 查询

        同样在 cli 容器中,查询初始化值:

peer chaincode query -C mychannel -n jiuxi -v v0 -c '{"Args": ["query", "a"]}'

image3.png

6.2 转账

        在 cli 容器中继续执行转账操作:

peer chaincode invoke -C mychannel -n jiuxi -v v0 -c '{"Args": ["invoke", "a", "b", "10"]}'

        After successful execution, the value of a query again account and found that had gone from 10,090.

        Since then, the entire block to build a successful chain network, and validate an example of a simple chain code (intelligent contracts). I do not know what you feel, there is no desire to scream, and if so, please help me to point a praise.

Guess you like

Origin blog.51cto.com/14625168/2466827