Query a Chaincode

post

/restproxy/api/v2/channels/{channelId}/chaincode-queries

Query a chaincode

Request

Supported Media Types
Path Parameters
Body ()
Request to query a chaincode
Root Schema : schema
Type: object
Show Source
Nested Schema : args
Type: array
Arguments for the chaincode
Show Source
Nested Schema : transientMap
Type: object
Additional Properties Allowed
Show Source
TransientMap for the chaincode
Back to Top

Response

Supported Media Types

200 Response

Operation successful
Body ()
Root Schema : schema
Type: object
Show Source
Nested Schema : result
Type: object
Show Source

400 Response

Bad Request

401 Response

Not authorized

403 Response

Forbidden

404 Response

Invalid parameters

500 Response

Service unavailable
Back to Top

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/default/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 restproxy 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.

Back to Top