需要升级docker中的go版本
wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
sudo rm -rf /opt/go
sudo tar -C /opt -xzvf go1.10.3.linux-amd64.tar.gz
export $GOPATH=/opt/gopath
export $GOROOT=/usr/local/go
往docker中传文件:
docker inspect -f '{{.Id}}' cli
37ee6f7d4c3d97d878c3697ce8f449c1b6f74538fe9a5d8350fe06ed75f0d46b
docker cp mychaincode/ 37ee6f7d4c3d97d878c3697ce8f449c1b6f74538fe9a5d8350fe06ed75f0d46b:/opt/gopath/src/
docker cp go1.10.3.linux-amd64.tar.gz 37ee6f7d4c3d97d878c3697ce8f449c1b6f74538fe9a5d8350fe06ed75f0d46b:/root/
docker cp /opt/gopath/src/mychaincode 37ee6f7d4c3d97d878c3697ce8f449c1b6f74538fe9a5d8350fe06ed75f0d46b:/opt/gopath/src
部署:
peer chaincode install -n tang -v 8.6 -p mychaincode
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 mychannel -n tang -v 8.6 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
查询
peer chaincode query -C mychannel -n tang -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 mychannel -n tang -c '{"Args":["deposit","a","100","deposit"]}'
升级
peer chaincode upgrade -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 mychannel -n tang -v 8.6 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
运行和启动Fabric例子
1、下载hyperledger/fabric-sample
2、切换到release-1.0
3、下载bin到fabric-sample目录
3、进入first-network文件夹
4、关闭
./byfn.sh -m down
5、初始化
./byfn.sh -m generate
⽣成初始区块
$ ../bin/cryptogen generate --config=./crypto-config.yaml
$ export FABRIC_CFG_PATH=$PWD
$ ../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
⽣成应⽤通道的配置信息
$ export CHANNEL_NAME=mychannel
$ ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -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 命令
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer #
command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep
$TIMEOUT' volumes
操作网络
$ CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=600 docker-compose -f docker-compose-cli.yaml up -d
更多区块链精品课程 请到优米 IT 学院: https://shop557190130.taobao.com/
创建和加⼊通道
进⼊ docker 容器
$ docker exec -it cli bash
创建通道
$ 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
加⼊通道
$ peer channel join -b mychannel.block
链上代码 (链码)
安装链码
$ 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"]}’