Query a Chaincode
post
/restproxy/api/v2/channels/{channelName}/chaincode-queries
Query a chaincode
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 the Hyperledger Fabric enrollment to be used
-
sameOrgEndorser:
boolean
Default Value:
false
Whether it should select a peer of this org only. When set to true, the peers cannot be specified. -
timeout:
integer(int64)
Default Value:
18000
Timeout in ms for the chaincode to invoke -
transientMap:
object transientMap
Additional Properties Allowed: additionalPropertiesTransient map for the chaincode
Nested Schema : transientMap
Type:
object
Additional Properties Allowed
Show Source
Transient map for the chaincode
Response
Supported Media Types
- application/json
200 Response
Successful operation
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 -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:
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.