All Products
Search
Document Center

Blockchain as a Service:Invoke Transaction to Query Data

Last Updated:Jul 21, 2022

Invoke the smart contract to query the data in the blockchain network.

API

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

Url Path Args

Description

network

Fabric channel name

Request Parameter

URL Query

URL Query Args

Type

Required

Description

timeout

Integer

False

Maximum wait time in seconds to confirm whether submitted transaction is success(valid) or not. Default is 180.

Body

Content-Type: application/json

Name

Type

Required

Description

chaincode

String

True

The Name of target smart contract

args

List<String>

False

The arguments list of the smart contract call. When this parameter(args) is not empty, the function and byte_args parameters are ignored.

function

String

False

The name of smart contract function to call

byte_args

List<String>

False

Base64-encoded smart contract call arguments (without function name)

transient

Map<String, String>

False

The transient map of this call, Key is the name, and Value is data

byte_transient

Map<String, String>

False

The transient map of this call, Key is the name, and Value is base64-encoded data(this parameter will merge with transient and overrides the Key in it)

Response

Name

Type

Description

Success

Boolean

Indicating if the request was successful.

  • true: success

  • false: failure

Error

Error

Please see the table below

Result

Response

Please see the table below

Error

Name

Type

Description

code

Integer

Error Code

message

String

Error description

request_id

String

The id of this request

Response

Name

Type

Description

id

String

Transaction ID

status

String

Status code returned by smart contract (smart contract), which is returned according to the actual code, usually returns 200 to indicate success

event

List<Event>

List of blockchain events generated by the transaction

data

String

Base64-encoded data returned by smart contract

Event

Name

Type

Description

id

String

Event ID, unique within the channel

name

String

Event name

type

EventType

Event type(“Tx”, “Config”, “Contract”, “Block”), here is always “Contract”

content

String

When EventType is “Contract”, it is Base64 encoded event content

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\"],\"transients\":{\"key\":\"value\"}}"
Note

For how to obtain the Access Token, please refer to Generate Access Token. The key in the parameter transients is the parameter name, which is determined by the actual submitted data content, and the value is the parameter value corresponding to the parameter name.

Example of Normal Return

{
  "Success": true,
  "Result": {
    "id": "3f850796a57db7178f8e367cce736a228a8e77544ef5c92a564f9cf0ad8893c4",
    "status": "200",
    "events": [],
    "data": "YWxpeXVuMQ=="
  },
  "Error": {
    "code": 200,
    "message": "Success",
    "request_id": "5640793d-219e-4e2f-9725-988ce11ee6b6"
  }
}

Error Code

Please refer to Error Code