Help Center > > API Reference> BCS APIs> Chaincode Invoking API

Chaincode Invoking API

Updated at: Sep 27, 2019 GMT+08:00

Function

Invokes and queries the instantiated chaincodes of deployed BCS services.

URI

POST /v1/chaincode/operation

Request Message

Table 1 Message fields

Parameter

Mandatory

Type

Description

channelId

Yes

String

Channel ID in a blockchain.

chaincodeId

Yes

String

Chaincode ID.

chaincodeVersion

No

String

Chaincode version.

userId

Yes

String

User ID issued by the organization CA. The default value generated for BCS is User1 now.

orgId

Yes

String

Organization ID in a blockchain.

orgPeers

Yes

String

A character string consisting of the organization ID and domain name of each peer in an organization. The format is as follows:

[{"orgId":"7258adda1803f4137eff4813e7aba323018200c5","peerDomainName":"peer-7258adda1803f4137eff4813e7aba323018200c5-0.peer-7258adda1803f4137eff4813e7aba323018200c5.default.svc.cluster.local"}]

opmethod

Yes

String

Purpose, that is, to invoke or query chaincodes.

args

Yes

String

Arguments, for example, ["Invoke", "a", "b", "1"]

timestamp

Yes

String

For example, 2018-10-31T17:28:16+08:00.

cert

Yes

String

User certificate file, which is uploaded in the form of a character string.

NOTE:

To ensure that only authorized invocation entities can invoke chaincodes, the user private key (downloaded by following Downloading the User Certificate) and the ECDSA encryption method must be used to encrypt and sign the SHA256 hash of the entire request body. The encrypted and signed hash is transmitted using the x-bcs-signature-sign parameter in the request header.

Response Message

  • If opmethod is invoke, the transactionID encrypted and encoded using Base64 is returned.
  • If opmethod is query, the query result returned by the chaincode is also encrypted and encoded using Base64.

Example

Invoking a chaincode

  • Example request
    {
      "channelId": "testchannel",
      "chaincodeId": "zmmcode",
      "chaincodeVersion": "1.0",
      "userId": "User1",
      "orgId": "7258adda1803f4137eff4813e7aba323018200c5", 
      "orgPeers": "[{"orgId":"7258adda1803f4137eff4813e7aba323018200c5", "peerDomainName":"peer-7258adda1803f4137eff4813e7aba323018200c5-0.peer-7258adda1803f4137eff4813e7aba323018200c5.default.svc.cluster.local"}]",
      "opmethod": "invoke",
      "args": "[\"invoke\",\"a\",\"b\",\"1\"]",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izyDZYR4rT2q0nzjFaiW+YfV5FBjAIgNalKUe3rIwXJvXORV4ZXurEua2Ag\nQmhcjRnVwPTjpTE=\n-----END CERTIFICATE-----\n"
    }
  • Example response
     After  invoke the count of a is 188  b is  262

Status Code

For details, see Status Code.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel