Blockchain as a Service:Invoke Transaction to Query Data

更新时间:
复制 MD 格式

Invokes a smart contract (chaincode) to query data in a Fabric channel.

Request

POST /api/v1/networks/{network}/transactions/query

Path parameters

ParameterDescription
networkThe name of the Fabric channel.

Query parameters

ParameterTypeRequiredDescription
timeoutIntegerNoThe maximum number of seconds to wait for the transaction to be confirmed as valid. Default value: 180.

Request body

Content-Type: application/json

ParameterTypeRequiredDescription
chaincodeStringYesThe name of the target smart contract.
argsList\<String\>NoThe arguments for the smart contract call. If this parameter is specified, the function and byte_args parameters are ignored.
functionStringNoThe name of the smart contract function to call.
byte_argsList\<String\>NoBase64-encoded arguments for the smart contract call, excluding the function name.
transientMap\<String, String\>NoThe transient map for the call. Each entry consists of a key (the parameter name) and a value (the parameter data).
byte_transientMap\<String, String\>NoThe transient map for the call, where each value is Base64-encoded. This parameter is merged with transient and overrides any duplicate keys.

Response

FieldTypeDescription
SuccessBooleanIndicates whether the request succeeded. Valid values: true (success), false (failure).
ErrorErrorThe error details. See Error.
ResultResponseThe query result. See Result.

Error

FieldTypeDescription
codeIntegerThe error code.
messageStringThe error description.
request_idStringThe request ID.

Result

FieldTypeDescription
idStringThe transaction ID.
statusStringThe status code returned by the smart contract. Typically 200 indicates success.
eventList\<Event\>The blockchain events generated by the transaction.
dataStringThe Base64-encoded data returned by the smart contract.

Event

FieldTypeDescription
idStringThe event ID, unique within the channel.
nameStringThe event name.
typeEventTypeThe event type. Valid values: Tx, Config, Contract, Block. For query transactions, this value is always Contract.
contentStringThe 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.