Invokes a smart contract (chaincode) to query data in a Fabric channel.
Request
POST /api/v1/networks/{network}/transactions/query
Path parameters
| Parameter | Description |
|---|
network | The name of the Fabric channel. |
Query parameters
| Parameter | Type | Required | Description |
|---|
timeout | Integer | No | The maximum number of seconds to wait for the transaction to be confirmed as valid. Default value: 180. |
Request body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|
chaincode | String | Yes | The name of the target smart contract. |
args | List\<String\> | No | The arguments for the smart contract call. If this parameter is specified, the function and byte_args parameters are ignored. |
function | String | No | The name of the smart contract function to call. |
byte_args | List\<String\> | No | Base64-encoded arguments for the smart contract call, excluding the function name. |
transient | Map\<String, String\> | No | The transient map for the call. Each entry consists of a key (the parameter name) and a value (the parameter data). |
byte_transient | Map\<String, String\> | No | The transient map for the call, where each value is Base64-encoded. This parameter is merged with transient and overrides any duplicate keys. |
Response
| Field | Type | Description |
|---|
Success | Boolean | Indicates whether the request succeeded. Valid values: true (success), false (failure). |
Error | Error | The error details. See Error. |
Result | Response | The query result. See Result. |
Error
| Field | Type | Description |
|---|
code | Integer | The error code. |
message | String | The error description. |
request_id | String | The request ID. |
Result
| Field | Type | Description |
|---|
id | String | The transaction ID. |
status | String | The status code returned by the smart contract. Typically 200 indicates success. |
event | List\<Event\> | The blockchain events generated by the transaction. |
data | String | The Base64-encoded data returned by the smart contract. |
Event
| Field | Type | Description |
|---|
id | String | The event ID, unique within the channel. |
name | String | The event name. |
type | EventType | The event type. Valid values: Tx, Config, Contract, Block. For query transactions, this value is always Contract. |
content | String | The Base64-encoded event content. Applies when the event type is Contract. |
Examples
Request example
curl -X POST "http://your.gateway.endpoint/api/v1/networks/channel3/transactions/query" \
-H "accept: application/json" \
-H "Authorization: Bearer <your-access-token>" \
-H "Content-Type: application/json" \
-d '{"chaincode":"sacc","args":["get","provider"],"transient":{"key":"value"}}'
To get the access token, see Generate access token. In the transient parameter, each key is a parameter name determined by the data being submitted, and each value is the corresponding data.
Response example
{
"Success": true,
"Result": {
"id": "3f850796a57db7178f8e367cce736a228a8e77544ef5c92a564f9cf0ad8893c4",
"status": "200",
"events": [],
"data": "YWxpeXVuMQ=="
},
"Error": {
"code": 200,
"message": "Success",
"request_id": "5640793d-219e-4e2f-9725-988ce11ee6b6"
}
}
Error codes
For a full list of error codes, see Error code.