Invoke Chaincode Transaction on BYFN Channel

Q

How to Invoke Chaincode Transaction on BYFN Channel?

✍: FYIcenter.com

A

An instance of a chaincode can be viewed as an object of a class in an execution environment. It can hold transaction operations to manage its properties.

You can run the "peer chaincode invoke" command to invoke the "Invoke" operation of a given chaincode instance.

1. Verify instantiated chaincode:

$ docker exec -it cli bash

bash-4.4# echo $CORE_PEER_ADDRESS
peer0.org2.example.com:7051

bash-4.4# peer chaincode list -C mychannel --instantiated
Get instantiated chaincodes on channel mychannel:
Name: mycc, Version: 1.0, Path: github.com/chaincode/chaincode_example02/go/, \
   Escc: escc, Vscc: vscc

2. Invoke chaincode instance to transfer 10 from property:

bash-4.4# 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 mychannel -n mycc \
   --peerAddresses peer0.org1.example.com:9051 --tlsRootCertFiles \
   /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations\
   /org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
   --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles \
   /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations\
   /org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
   -c '{"Args":["invoke","a","b","10"]}'

Error: error getting endorser client for invoke: endorser client failed 
to connect to peer0.org1.example.com:9051: failed to create new 
connection: connection error: desc = "transport: error while dialing: 
dial tcp 172.18.0.14:9051: connect: connection refused"

The command failed, because there is a typo in the command provided from "Building Your First Network" document provided from: https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html. The port number should 7051, not 9051.

bash-4.4# 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 mychannel -n mycc \
   --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles \
   /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations\
   /org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
   --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles \
   /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations\
   /org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
   -c '{"Args":["invoke","a","b","10"]}'

Error: could not assemble transaction: ProposalResponsePayloads do not 
match - proposal response: version:1 response:<status:200 > payload:"\n 
?\361b\342\357\345+\371\344\332\203\242F6\262\347\014<i\241\302\247\272\326
_t(\250\337+\033\303\022\214\001\nx\0221\n\n_lifecycle\022#\n!\n\037namespa
ces/fields/mycc/Sequence\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\01
0\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002
\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310
\001\"\013\022\004mycc\032\0031.0" 
endorsement:<endorser:"\n\007Org1MSP\022\252\006
-----BEGIN CERTIFICATE-----
... peer0.org1.example.com certificate ...
-----END CERTIFICATE-----\n" 
signature:"0D\002 
>\236/\024\177\025/\017\266\321\227\271\223\240\321\316\256\340\256\225\203
\265BR\215\322M\014\223x\345g\002 
O\370\216n\267i\367\256\252kh\007O\207[+u\240\220L@%\351\237'\252\237\024\3
45\320?*" >

The command failed again, because there chaincode installed on peer0.org1 and peer0.org2 either missing or does no match. See the next tutorial on how to resolve this error.

 

BYFN CLI "peer" Command Prefix

Query Chaincode Property on BYFN Channel

BYFN (Build Your First Network)

⇑⇑ Hyperledger Tutorials

2020-09-30, 1145🔥, 0💬