Query a Chaincode
post
/restproxy/api/v2/channels/{channelName}/chaincode-queries
Query a chaincode. This endpoint is used to invoke any query function supported by the chaincode application that is already installed and instantiated on a channel.
Request
Supported Media Types
- application/json
Path Parameters
-
channelName(required): string
ID of the channel
Request to query a chaincode
Root Schema : schema
Type:
Show Source
object
-
args(required):
array args
Arguments for the chaincode
-
chaincode(required):
string
Name of the chaincode
-
peer:
string
Endpoint of the target peer
-
role:
string
Name of Hyperledger Fabric enrollment to be used
-
sameOrgEndorser:
boolean
Default Value:
false
Specify if it should select a peer of this organization only. When set to true, the peer field cannot be specified. -
timeout:
integer(int64)
Default Value:
18000
Timeout in ms for the chaincode to invoke -
transientMap:
object transientMap
Additional Properties Allowed: additionalPropertiesTransientMap for the chaincode
Nested Schema : transientMap
Type:
object
Additional Properties Allowed
Show Source
TransientMap for the chaincode
Response
Supported Media Types
- application/json
200 Response
Operation successful
Root Schema : schema
Type:
Show Source
object
-
error:
string
Default Value:
-
result:
object result
-
returnCode(required):
string
Allowed Values:
[ "Success", "Failure" ]
Nested Schema : result
Type:
Show Source
object
-
encode(required):
string
Allowed Values:
[ "UTF-8", "JSON", "base64" ]
-
message:
string
-
payload(required):
400 Response
Bad request
401 Response
Not authorized
403 Response
Forbidden
404 Response
Invalid parameters
500 Response
Service unavailable
Examples
This endpoint is used to invoke any function supported by the chaincode application that is already installed and instantiated on a channel.
Note:
You cannot use this endpoint to invoke any function that modifies the ledger values.The following example shows how to invoke a chaincode query function by submitting a GET request on the REST resource using cURL.
curl -v -u <username>:<password> -X POST \ "https://<restproxy of your Blockchain instance>/api/v2/channels/<channel_name>/chaincode-queries" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @<JSON file with the request parameters>
For example,
curl -v -u <username>:<password> -X POST \ "https://myvm.oracle.com:10001/restproxy/api/v2/channels/default/chaincode-queries" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @file.json
The contents of
file.json
are:{ "chaincode": "obcs-example02", "args":["query","b"], "timeout": 18000, "peer": "myvm.oracle.com:10036" }
Where:
chaincode
is the chaincode ID of the Balance Transfer sample chaincode.args
specify the chaincode query function to be invoked along with it's parameters.timeout
specifies the maximum number of milliseconds for the transaction to timeout.peer
indicates the peer node for this transaction.
Note:
You can find the REST proxy value of your Blockchain instance from the Nodes tab of your instance console.Example of the Response Body
The following example shows the contents of the response body in JSON format:
{ "returnCode": "Success", "error": "", "result": { "payload": 2200, "encode": "JSON" } }
In this case, the value returned for payload
, that is, 2200 is the
result returned by the chaincode query function specified in the request.