操作系统:阿里云Ubuntu16.04
Git、Golang
Docker环境支持:docker、docker-compose
Fabric组件Docker镜像
fabric-samples源码库
Nodejs: 8.9.4
#先看这个搭建Hyperledger Fabric基础环境
https://blog.csdn.net/holechain/article/details/88795776
#(看到安装docker-compose完成即可,接下来看此篇)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source ~/.bashrc
nvm ls
nvm install
安装指定版本的 nodenvm install v8.9.4
nvm list
v6.9.5
,目前->
所指是v6.9.5
版本,需要切换成v8.9.4
版本nvm use v8.9.4
wget wget https://nodejs.org/dist/v8.9.4/node-v8.9.4-linux-x64.tar.gz
tar -zxvf node-v8.9.4-linux-x64.tar.gz
sudo mv node-v8.9.4-linux-x64 /usr/local/node
sudo ln -s /usr/local/node/bin/node /usr/local/bin/node
sudo ln -s /usr/local/node/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
Node.js
并设置镜像加速node -v
npm -v
npm config set registry https://registry.npm.taobao.org
fabric-samples
目录mkdir -p github.com/hyperledger/fabric-samples
fabric-samples
下git clone https://github.com/hyperledger/fabric-samples.git
git tag
git checkout release1.0
git branch
git branch -d release1.0
fabric-samples
目录下bin
目录中所需要的文件)https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric
wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.0.5/hyperledger-fabric-linux-amd64-1.0.5.tar.gz
fabric-samples
目录下tar -zxvf hyperledger-fabric-linux-amd64-1.0.5.tar.gz -C /home/go/src/github.com/hyperledger/fabric-samples
dockerimages
执行文件复制并在fabric-samples
中创建init.shhttps://raw.githubusercontent.com/hyperledger/fabric/v1.0.5/scripts/bootstrap.sh
vim init.sh
chmod -R 777 init.sh
1.0.5
是指定fabric的docker镜像版本)./init.sh 1.0.5
first-network
目录中cd first-network
./byfn.sh -m down
./byfn.sh -m generate
../bin/cryptogen generate --config=./crypto-config.yaml
first-network
目录下设置变量:(设置工作目录)export FABRIC_CFG_PATH=$PWD
-profile
指定联盟配置,outputBlock
指定存放的位置../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
-profile
指定业务联盟,-outputCreateChannelTx
指存放的路径,创建的名字叫mychannel
export CHANNEL_NAME=mychannel
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channelID $CHANNEL_NAME
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
编辑docker-compose-cli.yaml
,注释command
命令
vim docker-compose-cli.yaml
CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=600 docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash
-o
指定与哪个orderer节点通信,-c
指定创建的通道名称,-f
指定使用的文件)export CHANNEL_NAME=mychannel
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker logs orderer.example.com
peer channel join -b mychannel.block
peer channel list
-n
指定链码安装的名字,-v
指定version,-l
指定使用语言,-p
指定安装链码的所在路径)peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
peer chaincode instantiate \
-o orderer.example.com:7050 \
--tls $CORE_PEER_TLS_ENABLED \
--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 $CHANNEL_NAME \
-n mycc \
-v 1.0 \
-c '{"Args":["init","a","100","b","200"]}' \
-P "OR ('Org1MSP.member','Org2MSP.member')"
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke \
-o orderer.example.com:7050 \
--tls $CORE_PEER_TLS_ENABLED \
--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 $CHANNEL_NAME \
-n mycc \
-c '{"Args":["invoke","a","b","10"]}'
点击exit
退出docker
容器
./byfn.sh -m down
###参数说明:
进入fabric-samples
目录下的fabcar
目录中
cd fabric-samples/fabcar
cat package.json
docker rm -f $(docker ps -a)
docker network prune
docker rmi dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba
fabcar
目录中安装客户端npm install
./startFabric.sh node
node enrollAdmin.js
node registerUser.js
node query.js
queryAllCars
更改为queryCar
并将特定的“Key” 传递给args参数。在这里,我们使用CAR4
。 所以我们编辑后的query.js程序现在应该包含以下内容:node query.js
./byfn.sh -m down
出现错误的解决方法:https://segmentfault.com/a/1190000014221967
node registerUser.js
出现错误:Failed to register: Error: fabric-ca request register failed with errors [[{"code":0,"message":"No identity type provided. Please provide identity type"}]]
node registerUser.js
文件vim node registerUser.js
returnfabric_ca_client.register({enrollmentID: 'user1', affiliation:'org1.department1'}, admin_user);
替换为下方代码returnfabric_ca_client.register({enrollmentID: 'user1', affiliation:'org1.department1',role: 'client'}, admin_user);
marbles . step 4 error error: Caught exception: TypeError: Cannot read property 'getConnectivityState' of undefined
出错npm uninstall grpc
rm -rf node_modules/
npm install
https://github.com/IBM-Blockchain/marbles/blob/master/docs/use_local_hyperledger.md
https://hyperledger-fabric.readthedocs.io/en/release-1.0/chaincode4noah.html
https://hyperledger-fabric.readthedocs.io/en/release-1.0/write_first_app.html