Tools, FAQ, Tutorials:
Interact with "fabcar" Chaincode on CLI
How to Interact "fabcar" Chaincode on CLI?
✍: FYIcenter.com
After you started the WYFA network properly, you will have
the "fabcar" chaincode running on "mychannel" on the peer0.org1.example.com
peer container.
You can now interact with the "fabcar" chaincode from the CLI container as shown below.
1. Connect to CLI container:
$ docker exec -it cli bash root@262918fdcbc0:/opt/gopath/src/github.com/hyperledger/fabric/peer# cd root@262918fdcbc0:~#
2. Make sure that the "fabcar" chaincode is instantiated:
root@262918fdcbc0:~# peer chaincode list --instantiated -C mychannel Get instantiated chaincodes on channel mychannel: Name: fabcar, Version: 1.0, Path: github.com/fabcar/go, Escc: escc, Vscc: vscc
3. Try the query method on the chaincode:
root@262918fdcbc0:~# peer chaincode query -C mychannel -n fabcar -c '{"Args":[]}'
Error: endorsement failure during query. response: status:500
message:"Invalid Smart Contract function name."
The error is expected, since the chaincode does not implement the "Query" method.
4. Try the invoke method on the chaincode:
root@262918fdcbc0:~# peer chaincode invoke -C mychannel -n fabcar -c '{"Args":[]}'
[chaincodeCmd] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
Error: endorsement failure during invoke. response: status:500 message:"Invalid Smart Contract function name."
This error is also expected, since chaincode's Invoke method requires the function name to perform a pre-defined task.
5. Try the invoke method with initLedger function on the chaincode:
root@262918fdcbc0:~# peer chaincode invoke -C mychannel -n fabcar -c '{"function":"initLedger","Args":[]}'
[chaincodeCmd] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
[chaincodeCmd] chaincodeInvokeOrQuery -> INFO 002 Chaincode invoke successful. result: status:200
The chaincode executed the initLedger and returned a successful code.
6. Try the invoke method with queryAllCars function on the chaincode:
root@262918fdcbc0:~# peer chaincode invoke -C mychannel -n fabcar -c '{"function":"queryAllCars","Args":[]}'
[chaincodeCmd] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
[chaincodeCmd] chaincodeInvokeOrQuery -> INFO 002 Chaincode invoke successful. result: status:200 \
payload:"[
{\"Key\":\"CAR0\", \"Record\":{\"colour\":\"blue\",\"make\":\"Toyota\",\"model\":\"Prius\",\"owner\":\"Tomoko\"}},
{\"Key\":\"CAR1\", \"Record\":{\"colour\":\"red\",\"make\":\"Ford\",\"model\":\"Mustang\",\"owner\":\"Brad\"}},
{\"Key\":\"CAR2\", \"Record\":{\"colour\":\"green\",\"make\":\"Hyundai\",\"model\":\"Tucson\",\"owner\":\"Jin Soo\"}},
...
]"
The chaincode executed the queryAllCars and returned a payload message.
⇒ Verify World State in CouchDB
⇐ fabcar.go - The "fabcar" Chaincode
2020-02-20, ∼3019🔥, 0💬
Popular Posts:
How to use the "return-response" Policy statement to build the response from scratch for an Azure AP...
How To Remove Slashes on Submitted Input Values in PHP? By default, when input values are submitted ...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
How to Install Docker Desktop on Windows 10? You can follow this tutorial to Install Docker Desktop ...