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:
falseSpecify 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:
18000Timeout in ms for the chaincode to invoke -
transientMap:
object transientMap
Additional Properties Allowed: additionalPropertiesTransientMap for the chaincode
Nested Schema : transientMap
Type:
objectAdditional 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
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
401 Response
Unauthorized
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
403 Response
Forbidden
404 Response
Not Found
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
500 Response
Internal Server Error
Headers
-
opc-request-id: string
Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
Root Schema : Error
Type:
objectError Information.
Show Source
-
code(required):
string
A short error code that defines the error, meant for programmatic parsing.
-
message(required):
string
A human-readable error string.
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 -X POST \ "https://<restproxy of your Blockchain instance>/api/v2/channels/<channel_name>/chaincode-queries" \ -H "Authorization: Bearer <OAuth_access_ token>" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ --data @<JSON file with the request parameters>
For example,
curl -v -X POST \ "https://myvm.oracle.com:10001/restproxy/api/v2/channels/default/chaincode-queries" \ -H "Authorization: Bearer mF_9.B5f-4.1JqM" \ -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:
chaincodeis the chaincode ID of the Balance Transfer sample chaincode.argsspecify the chaincode query function to be invoked along with it's parameters.timeoutspecifies the maximum number of milliseconds for the transaction to timeout.peerindicates 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.