fabric1.4.3单机环境搭建教程(三)

Fabric中链码的使用

1.确认网络是否处于开启状态

$ sudo docker ps

2. 使用docker-compose命令启动网络

$ sudo docker-compose -f docker-compose-cli.yaml up -d

3.使用docker exec命令进入CLI容器

$ sudo docker exec -it cli bash

4.设置环境变量

$ export CHANNEL_NAME=mychannel

5.创建通道

peer channel create -o orderer.example.com:7050 -c mychannel -f
./channel-artifacts/channel.tx --tls –cafile
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

6.将节点加入通道

peer channel join -b mychannel.block

7.更新2个组织锚节点(如以下内容)

peer channel update -o orderer.example.com:7050 -c mychannel -f
./channel-artifacts/Org1MSPanchors.tx --tls –cafile
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

8.安装链码

$ peer chaincode install -n mycc -v 1.0 -p
github.com/chaincode/chaincode_example02/go/

9.实例化链码

$ peer chaincode instantiate -o orderer.example.com:7050 --tls
–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.peer’,‘Org2MSP.peer’)”

10.查询链码

$ peer chaincode query -C $CHANNEL_NAME -n mycc -c
‘{“Args”:[“query”,“a”]}’

11.调用链码

$ 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 $CHANNEL_NAME -n mycc -c ‘{“Args”:[“invoke”,“a”,“b”,“10”]}’

12.查询a账户

$ peer chaincode query -C $CHANNEL_NAME -n mycc -c
‘{“Args”:[“query”,“a”]}’

你可能感兴趣的:(区块链,区块链)