链码操作

1.创建通道:

peer channel create -o orderer.wisedu.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx

2.加入通道:在对应peer节点下执行(要想加入某通道,必须有该通道的block文件)

peer channel join -b $CHANNEL_NAME.block

3.更新锚节点:

peer channel update -o orderer.6.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx

其中,${CORE_PEER_LOCALMSPID}对应当前操作的peer节点所属MSPID,取值例如:{“Org1MSP”,"Org2MSP"}

4.安装链码(在每个peer节点):

peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

5.实例化链码(只需在一个peer节点实例化一次):

peer chaincode instantiate -o orderer.wisedu.com:7050 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR    ('Org1MSP.peer','Org2MSP.peer')"

6.查询

peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

7.转账

peer chaincode invoke -o orderer.wisedu.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'

 

8.$CHANNEL_NAME.block从docker中拷贝出来

sudo docker cp [879433a63002]:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block /home/shirly/projects/fabric/examples/e2e_cli/channel-artifacts/

其中, [879433a63002]是链码所在容器ID,即peer客户端的cli

9.从宿主机拷贝进去docker

sudo docker cp /home/shirly/projects/fabric/examples/e2e_cli/channel-artifacts/mychannel.block [xxxxxxxxxxx]:/opt/gopath/src/github.com/hyperledger/fabric/peer/

其中, [xxxxxxxxxxx]也是对应peer节点的客户端cli容器的ID

 

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