Fabric智能合约编译与测试环境搭建

1.创建docker-compose-dev.yaml
membersrvc:
  image: hyperledger/fabric-membersrvc
  ports:
    - "7054:7054"
  command: membersrvc
vp0:
  image: hyperledger/fabric-peer
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=false
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
  links:
    - membersrvc
  command: sh -c "sleep 5; peer node start --peer-chaincodedev"
  
  
2.启动节点
docker-compose -f docker-compose-dev.yaml up




3.进入节点
docker exec -it pbft_vp0_1 bash


4.进入需要编译的智能合约文件目录,如下示例
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02


5.进行编译
go build   //编译代码,生成chaincode_example02可执行程序。编译成功将不显示任何信息,失败会显示失败信息


6.发布合约
CORE_CHAINCODE_ID_NAME=mycc01 CORE_PEER_ADDRESS=172.17.0.3:7051 ./chaincode_example02   //发布chaincode,并为其注册一个名称CORE_CHAINCODE_ID_NAME。如果发布成功会在打印信息中显示[shim] DEBU : Received REGISTERED, ready for invocations




7.进行正常合约的init,invoke,query操作
peer chaincode deploy -u jim -n mycc -c '{"Args": ["init", "a","100", "b", "200"]}'





你可能感兴趣的:(Fabric)