我是靠谱客的博主 糊涂水壶,最近开发中收集的这篇文章主要介绍108-Fabric全过程,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

 

先阿里云买个香港服务器

装个Ubuntu18.04

开始吧

 

 

 

 

 

 

 

 

有一个很烦的东西,就是node和npm

我先装了,看到就想吐

更新一下

apt update

 

 

apt install npm

 

 

 

 

npm install -g npm

 

 

 

 

 

 

apt install git

 

 

 

 

 

 

安装docker

 

 

 

 

 

 

 

安装fabric镜像

bootstrap.sh

https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh

chmod 777 bootstrap.sh

./bootstrap.sh

 

 

 

 

 

 

 

安装docker-compose

https://github.com/docker/compose/releases/

我现在的最新版本是1.27.4

但是我往前翻到1.25.4才找到这条命令

curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

 

 

 

 

 

 

好了,准备工作全部做完了,

我觉得可以在这边存一个快照

挺好的

 

 

 

 

 

启动网络吧

./network.sh up

 

 

 

然后创建下channel

./network.sh createChannel -c mychannel

 

 

 

 

然后我们改一下链码

删除一下test文件夹

npm install一下

 

 

 

 

 

然后打包安装链码

export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/


peer version

 

 

 

 

 

打包一下

peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-javascript/ --lang node --label basic_1.0

 

 

 

 

切换Org1

export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

 

 

 

 

 

安装一下

peer lifecycle chaincode install basic.tar.gz

 

 

 

 

 

看下安装状态

peer lifecycle chaincode queryinstalled

 

 

 

 

拿下ID

export CC_PACKAGE_ID=basic_1.0:69de748301770f6ef64b42aa6bb6cb291df20aa39542c3ef94008615704007f3

export CC_PACKAGE_ID=basic_1.0:f3b7ff213eace35090e98f6046c502af759f964bae46a0c3d5d9281b8c9bef26

 

 

 

 

 

 

验证一下链码

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

 

 

 

 

 

切换Org2

export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051

 

 

 

 

 

 

安装一下

peer lifecycle chaincode install basic.tar.gz

 

 

 

 

 

验证一下

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

 

 

 

 

 

 

查看提交状态

peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json

 

 

 

 

 

 

 

提交链码

peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt

 

 

 

 

 

 

启动链码

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

 

 

 

 

 

查询一下

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

 

 

 

 

 

 

现在改一下Application

改一下app.js

然后npm install一下

 

 

 

 

 

 

启动一下

node app.js

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最后

以上就是糊涂水壶为你收集整理的108-Fabric全过程的全部内容,希望文章能够帮你解决108-Fabric全过程所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部