Fabric 环境安装
我安装的时候遇到很多问题,也不会解决,我就是将fabric文件夹删除重新下,然后一步步再按,反正最后是能运行。
官网的安装方法http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
1.Go语言安装
sudo apt-get install golang
sudo vim ~/.bashrc
结尾输入以下
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GOPATH=$HOME/MyGo
重启终端输入go env 查看配置是否成功
<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="图片_x0020_6" o:spid="_x0000_i1043" type="#_x0000_t75" style='width:414.75pt;height:249.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
具体环境变量配置参考window上的
2.Docker安装
sudo apt install docker.io //docker安装
sudo usermod -aG docker $USER //更改用户权限
sudo service docker start //启动docker
chmod 777 /var/run/docker.sock //进入root操作
3.Docker-compose安装
sudo apt install python-pip
sudo pip install docker-compose
4.Fabric安装
4.1.Fabric源码下载
先在GOPATH路径下建立以下文件夹
<!--[if gte vml 1]><v:shape id="图片_x0020_8" o:spid="_x0000_i1042" type="#_x0000_t75" style='width:320.25pt;height:31.5pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
进入hyperLedger文件夹下在终端输入:
git clone https://github.com/hyperledger/fabric.git //从github上下载fabric
下载完成后hyperLedger文件夹下会多出一个fabric文件夹
4.2. Fabric Docker镜像的下载
进入如下文件夹
<!--[if gte vml 1]><v:shape id="图片_x0020_9" o:spid="_x0000_i1041" type="#_x0000_t75" style='width:369pt;height:33.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
输入
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
文件较大,等待
下载完成后输入 docker images 可查看下载好的镜像
<!--[if gte vml 1]><v:shape id="图片_x0020_10" o:spid="_x0000_i1040" type="#_x0000_t75" style='width:414.75pt;height:198.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
4.3. 启动Fabric网络并完成ChainCode的测试
依旧在e2e_cli文件夹下运行终端输入
./network_setup.sh up
正常运行完出现如下界面,其中运行内容参考hyperledger技术与应用一书
<!--[if gte vml 1]><v:shape id="图片_x0020_1" o:spid="_x0000_i1039" type="#_x0000_t75" style='width:414.75pt;height:185.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image009.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
4.4. 测试Fabric网络
在官方例子中,channel名字是mychannel,链码的名字是mycc。我们首先进入CLI,我们重新打开一个命令行窗口,输入:
docker exec -it cli bash
查询a账户的余额:
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
可看出现在余额为90
<!--[if gte vml 1]><v:rect id="矩形_x0020_12" o:spid="_x0000_s1027" style='position:absolute;left:0;text-align:left; margin-left:.3pt;margin-top:95.5pt;width:69pt;height:9.75pt;z-index:251658240; visibility:visible;mso-wrap-style:square;mso-wrap-distance-left:9pt; mso-wrap-distance-top:0;mso-wrap-distance-right:9pt; mso-wrap-distance-bottom:0;mso-position-horizontal:absolute; mso-position-horizontal-relative:text;mso-position-vertical:absolute; mso-position-vertical-relative:text;v-text-anchor:middle' o:gfxdata="UEsDBBQABgAIAAAAIQC75UiUBQEAAB4CAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbKSRvU7DMBSF dyTewfKKEqcMCKEmHfgZgaE8wMW+SSwc27JvS/v23KTJgkoXFsu+P+c7Ol5vDoMTe0zZBl/LVVlJ gV4HY31Xy4/tS3EvRSbwBlzwWMsjZrlprq/W22PELHjb51r2RPFBqax7HCCXIaLnThvSAMTP1KkI +gs6VLdVdad08ISeCho1ZLN+whZ2jsTzgcsnJwldluLxNDiyagkxOquB2Knae/OLUsyEkjenmdzb mG/YhlRnCWPnb8C898bRJGtQvEOiVxjYhtLOxs8AySiT4JuDystlVV4WPeM6tK3VaILeDZxIOSsu ti/jidNGNZ3/J08yC1dNv9v8AAAA//8DAFBLAwQUAAYACAAAACEArTA/8cEAAAAyAQAACwAAAF9y ZWxzLy5yZWxzhI/NCsIwEITvgu8Q9m7TehCRpr2I4FX0AdZk2wbbJGTj39ubi6AgeJtl2G9m6vYx jeJGka13CqqiBEFOe2Ndr+B03C3WIDihMzh6RwqexNA281l9oBFTfuLBBhaZ4ljBkFLYSMl6oAm5 8IFcdjofJ0z5jL0MqC/Yk1yW5UrGTwY0X0yxNwri3lQgjs+Qk/+zfddZTVuvrxO59CNCmoj3vC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lpOV7+lwbvqWoI23fK4+toYcVx9zF2sL+BrP9 LwAAAP//AwBQSwMEFAAGAAgAAAAhAJxmRkG7AAAAJAEAACoAAABjbGlwYm9hcmQvZHJhd2luZ3Mv X3JlbHMvZHJhd2luZzEueG1sLnJlbHOEj80KwjAQhO+C7xD2btJ6EJEmvYjQq9QHCMk2LTY/JFHs 2xvoRUHwsjCz7DezTfuyM3liTJN3HGpaAUGnvJ6c4XDrL7sjkJSl03L2DjksmKAV201zxVnmcpTG KSRSKC5xGHMOJ8aSGtHKRH1AVzaDj1bmIqNhQaq7NMj2VXVg8ZMB4otJOs0hdroG0i+hJP9n+2GY FJ69elh0+UcEy6UXFqCMBjMHSldnnTUtXYGJhn39Jt4AAAD//wMAUEsBAi0AFAAGAAgAAAAhALvl SJQFAQAAHgIAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQSwECLQAUAAYA CAAAACEArTA/8cEAAAAyAQAACwAAAAAAAAAAAAAAAAA2AQAAX3JlbHMvLnJlbHNQSwECLQAUAAYA CAAAACEAcFqEnsYCAABGBgAAHwAAAAAAAAAAAAAAAAAgAgAAY2xpcGJvYXJkL2RyYXdpbmdzL2Ry YXdpbmcxLnhtbFBLAQItABQABgAIAAAAIQBn5CUzQQYAAM8ZAAAaAAAAAAAAAAAAAAAAACMFAABj bGlwYm9hcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQCcZkZBuwAAACQBAAAqAAAA AAAAAAAAAAAAAJwLAABjbGlwYm9hcmQvZHJhd2luZ3MvX3JlbHMvZHJhd2luZzEueG1sLnJlbHNQ SwUGAAAAAAUABQBnAQAAnwwAAAAA " filled="f" strokecolor="red" strokeweight="2.25pt"/><![endif]--><!--[if !vml]--><!--[endif]--><!--[if gte vml 1]><v:shape id="图片_x0020_2" o:spid="_x0000_i1038" type="#_x0000_t75" style='width:414.75pt;height:119.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image012.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
把a账户的余额再转20元给b账户
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","20"]}'
<!--[if gte vml 1]><v:shape id="图片_x0020_3" o:spid="_x0000_i1037" type="#_x0000_t75" style='width:414.75pt;height:167.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image014.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
再次查询a的余额
<!--[if gte vml 1]><v:rect id="矩形_x0020_13" o:spid="_x0000_s1026" style='position:absolute;left:0;text-align:left; margin-left:1.05pt;margin-top:92.65pt;width:69pt;height:9.75pt;z-index:251659264; visibility:visible;mso-wrap-style:square;mso-wrap-distance-left:9pt; mso-wrap-distance-top:0;mso-wrap-distance-right:9pt; mso-wrap-distance-bottom:0;mso-position-horizontal:absolute; mso-position-horizontal-relative:text;mso-position-vertical:absolute; mso-position-vertical-relative:text;v-text-anchor:middle' o:gfxdata="UEsDBBQABgAIAAAAIQC75UiUBQEAAB4CAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbKSRvU7DMBSF dyTewfKKEqcMCKEmHfgZgaE8wMW+SSwc27JvS/v23KTJgkoXFsu+P+c7Ol5vDoMTe0zZBl/LVVlJ gV4HY31Xy4/tS3EvRSbwBlzwWMsjZrlprq/W22PELHjb51r2RPFBqax7HCCXIaLnThvSAMTP1KkI +gs6VLdVdad08ISeCho1ZLN+whZ2jsTzgcsnJwldluLxNDiyagkxOquB2Knae/OLUsyEkjenmdzb mG/YhlRnCWPnb8C898bRJGtQvEOiVxjYhtLOxs8AySi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FAAGAAgAAAAhAJxmRkG7AAAAJAEAACoA AAAAAAAAAAAAAAAAngsAAGNsaXBib2FyZC9kcmF3aW5ncy9fcmVscy9kcmF3aW5nMS54bWwucmVs c1BLBQYAAAAABQAFAGcBAAChDAAAAAA= " filled="f" strokecolor="red" strokeweight="2.25pt"/><![endif]--><!--[if !vml]--><!--[endif]--><!--[if gte vml 1]><v:shape id="图片_x0020_4" o:spid="_x0000_i1036" type="#_x0000_t75" style='width:414.75pt;height:110.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image017.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
4.5. 关闭fabric网络
依旧在e2e_cli文件夹下运行终端输入
./network_setup.sh down
<!--[if gte vml 1]><v:shape id="图片_x0020_5" o:spid="_x0000_i1035" type="#_x0000_t75" style='width:414.75pt;height:153pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image019.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
5. 生成公私钥和证书
进入fabric文件夹下运行
make cryptogen
<!--[if gte vml 1]><v:shape id="图片_x0020_11" o:spid="_x0000_i1034" type="#_x0000_t75" style='width:414.75pt;height:93.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image021.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
进入examples/e2e_cli/文件夹下运行
../../build/bin/cryptogen generate --config=./crypto-config.yaml
<!--[if gte vml 1]><v:shape id="图片_x0020_12" o:spid="_x0000_i1033" type="#_x0000_t75" style='width:414.75pt;height:42pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image023.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->6. <!--[endif]-->生成创世区块和Channel配置区块
进入fabric文件夹下运行
make configtxgen
<!--[if gte vml 1]><v:shape id="图片_x0020_13" o:spid="_x0000_i1032" type="#_x0000_t75" style='width:414.75pt;height:89.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image025.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
6.1. 生成创世区块
进入examples/e2e_cli/文件夹下运行
../../build/bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
6.2. 生成Channel配置区块
../../build/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
../../build/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
../../build/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
运行完后可在channel-artifacts文件夹中看见如下文件
<!--[if gte vml 1]><v:shape id="图片_x0020_15" o:spid="_x0000_i1031" type="#_x0000_t75" style='width:308.25pt;height:84.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image027.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
<!--[if !supportLists]-->7. <!--[endif]-->配置Fabric环境的docker-compose文件
Orderer的配置是在base/docker-compose-base.yaml里面
Peer的配置是在base/docker-compose-base.yaml和peer-base.yaml里面
CLI在整个Fabric网络中扮演客户端的角色,我们在开发测试的时候可以用CLI来代替SDK,执行各种SDK能执行的操作。CLI会和Peer相连,把指令发送给对应的Peer执行。CLI的配置在docker-compose-cli.yaml中
我们这里全部采用默认配置,只把CLI中的command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT' 这行注释掉,后面我们手动执行。
我们要安装的ChainCode都是在fabric/examples/chaincode/go目录下,以后我们要开发自己的ChainCode,只需要把我们的代码复制到该目录即可
<!--[if !supportLists]-->8. <!--[endif]-->初始化Fabric环境
8.1. 启动Fabric环境的容器
docker-compose -f docker-compose-cli.yaml up -d
<!--[if gte vml 1]><v:shape id="图片_x0020_16" o:spid="_x0000_i1030" type="#_x0000_t75" style='width:414.75pt;height:165.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image029.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
8.2. 创建Channel
现在我们要进入cli容器内部,在里面创建Channel。先用以下命令进入CLI内部Bash:
docker exec -it cli bash
创建Channel的命令是peer channel create,我们前面创建Channel的配置区块时,指定了Channel的名字是mychannel,那么这里我们必须创建同样名字的Channel
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile $ORDERER_CA
<!--[if gte vml 1]><v:shape id="图片_x0020_17" o:spid="_x0000_i1029" type="#_x0000_t75" style='width:414.75pt;height:33.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image031.png" o:title="" croptop="55726f"/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
8.3. 各个Peer加入Channel
CLI默认连接的是peer0.org1 那么将其加入运行如下
peer channel join -b mychannel.block
其他的就需要修改CLI的环境变量,使其指向另外的Peer。比如我们要把peer1.org1加入mychannel
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
peer channel join -b mychannel.block
<!--[if gte vml 1]><v:shape id="图片_x0020_18" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:414.75pt;height:42.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image033.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
同样的方法,将peer0.org2加入mychannel:
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
peer channel join -b mychannel.block
最后把peer1.org2加入mychannel:
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
peer channel join -b mychannel.block
<!--[if !supportLists]-->9. <!--[endif]-->链上代码的安装与运行
以上,整个Fabric网络和Channel都准备完毕,接下来我们来安装和运行ChainCode
链上代码的安装需要在各个相关的Peer上进行,对于我们现在这种Fabric网络,如果4个Peer都想对Example02进行操作,那么就需要安装4次。
我们先切换到peer0.org1这个节点
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
使用peer chaincode install命令可以安装指定的ChainCode并对其命名:
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
9.1 Instantiate ChainCode实例化链上代码
实例化链上代码主要是在Peer所在的机器上对前面安装好的链上代码进行包装,生成对应Channel的Docker镜像和Docker容器。并且在实例化时我们可以指定背书策略。我们运行以下命令完成实例化:
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
<!--[if gte vml 1]><v:shape
id="图片_x0020_19" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:415.5pt;
height:39pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image035.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
9.2 在一个Peer上查询并发起交易
查询a账户
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
<!--[if gte vml 1]><v:shape
id="图片_x0020_20" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:415.5pt;
height:57.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image037.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
a账户的10元转给b
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
<!--[if gte vml 1]><v:shape id="图片_x0020_21" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:414.75pt; height:47.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\Users\ADMINI~1.BJX\AppData\Local\Temp\msohtmlclip1\01\clip_image039.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
同样我们可以在org2节点下操作,首先给peer0.org2安装链上代码:
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
其他操作同上
相关推荐
hyperledger_fabric环境安装参考手册,主要针对新手的建议安装配置
在“hyperledger-fabric环境”中,`hyperledger-fabric1.0`指的是Hyperledger Fabric的1.0版本。这个版本是Fabric项目的一个早期稳定版本,引入了许多核心特性,包括通道(Channels)、排序服务(Ordering Service)...
区块链fabric1.0环境搭建手册,完整配置流程,以及启动脚本等
在“fabric安装”这个主题中,我们将深入探讨如何在Python环境中安装和配置Fabric。首先,你需要确保你的系统已经安装了Python,因为Fabric是Python的一个库。通常,Python 2.7或更高版本(推荐使用Python 3.x)是...
在开始安装 Fabric 之前,确保您的系统环境已经准备好,并且满足 Fabric 的最低要求。由于 Fabric 是一个用于执行远程命令的任务自动化工具,主要用于简化通过 SSH 连接的服务器管理任务,因此它依赖于 Python 和...
本文将详细介绍如何在Fabric 2.2环境中安装和使用Hyperledger Explorer。 首先,我们关注的是Blockchain-Explorer的1.1.2版本,这是与Fabric 2.2兼容的一个稳定版本。你可以通过以下链接下载:...
在虚拟机Ubuntu上,部署hyperledger fabric 的环境搭建
Hyperledger Fabric 搭建 mac and centos7 压缩包包含 1.boot2docker.iso version:17.09.1-ce 2.fabric 官方例子 3.mac and centos7 一键安装脚本
fabric前期硬件资源准备、必要软件环境、源码安装、测试网络调测、blockchain-explore部署、合约部署实践【待续】
网络有时访问不了链接地址,可以直接分析这个脚本内容,从而下载及安装配置Fabric网络的测试环境。脚本中引用的下载文件:hyperledger-fabric-linux-amd64-2.4.4.tar.gz 及hyperledger-fabric-ca-linux-amd64-1.5.5....
"Hyperledger Fabric开发环境搭建(MacOS系统)" 在本文中,我们将讲述如何在MacOS系统上搭建Hyperledger Fabric开发环境。 Hyperledger Fabric是基于区块链技术的开源项目,旨在提供一个通用的分布式账本解决方案...
总的来说,部署Hyperledger Fabric环境涉及多个步骤,包括虚拟机的安装、Ubuntu和Docker的配置、源的更换,以及Hyperledger Fabric组件的安装和网络的创建。通过这个过程,我们可以搭建一个本地的区块链网络,用于...
区块链 Hyperledger Fabric v1.3 环境搭建,从环境准备到合约安装全流程。
Hyperledger Fabric 是用 Go 语言编写的,因此需要先安装 Go 语言环境。 **步骤:** 1. **下载 Go 安装包:** ```bash wget https://studygolang.com/dl/golang/go1.13.4.linux-amd64.tar.gz ``` 2. **解压...
本文档旨在详细介绍如何在本地搭建一个用于测试的Hyperledger Fabric环境,并集成fabric-java-sdk进行功能测试。我们将按照以下步骤进行: 1. **安装Java Development Kit (JDK)** 2. **安装Apache Maven** 3. **...
7. **安装和实例化链码**:链码是Fabric中的智能合约,需要在每个参与的Peer节点上安装,并在一个或多个通道上实例化。 8. **进行交易**:通过调用`peer chaincode invoke`或`peer chaincode query`命令,进行链码的...