Updated on 2023-10-09 GMT+08:00

Instantiating a Chaincode

Function

Instantiating a Chaincode

URI

POST /v2/agent/apis/chaincode/instantiate

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

chaincode_name

Yes

String

Chaincode name, which can contain 6 to 25 including lowercase letters and digits, and must start with a letter.

Minimum: 6

Maximum: 25

chaincode_version

Yes

String

Chaincode version. Only digits, periods (.), and hyphens (-) are allowed. The value must start and end with a digit, and the periods (.) and hyphens (-) cannot be adjacent.

channel_name

Yes

String

Channel name.

endorsement_policy

Yes

Policy object

Endorsement policy.

init_variable

Yes

InitArgs object

Initialization function and parameters.

private_data

No

String

Privacy protection configuration data, which is a JSON string. For example: [{"name":"kvstore-collection","policy":"OR('9b4ea44913e8eed42cb056177b46191e1d316678MSP.member','9b4ea44913e8eed42cb056177b46191e1d316678MSP.member')","requiredPeerCount":0,"maxPeerCount":2,"blockToLive":0,"memberOnlyRead":true}].

Table 3 Policy

Parameter

Mandatory

Type

Description

operation

Yes

String

Operator. OR: endorsement from any organization. AND: endorsement from all organizations.

group

Yes

Array of OrgPolicy objects

Endorsing organizations.

Table 4 OrgPolicy

Parameter

Mandatory

Type

Description

org_id

Yes

String

Organization ID.

category

No

String

Type, which can be member or *admin.

Table 5 InitArgs

Parameter

Mandatory

Type

Description

func_name

Yes

String

Initialization function.

args

Yes

Array of strings

Initialization parameters.

Response Parameters

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_message

String

Error description.

error_msg

String

Error description.

Example Requests

POST https://192.168.0.90:30603/v2/agent/apis/chaincode/instantiate

{
  "chaincode_name" : "gochaincode2",
  "chaincode_version" : "1.0",
  "channel_name" : "channel001",
  "endorsement_policy" : {
    "operation" : "AND",
    "group" : [ {
      "org_id" : "8cc7155fb1f26ebac1743f481386c14223be511f",
      "category" : "member"
    } ]
  },
  "init_variable" : {
    "func_name" : "init",
    "args" : [ "a", "200", "b", "100" ]
  },
  "private_data" : "[{\"name\": \"kvstore-collection\",\"policy\": \"OR('8cc7155fb1f26ebac1743f481386c14223be511fMSP.member','8cc7155fb1f26ebac1743f481386c14223be511fMSP.member')\",\"requiredPeerCount\": 0,\"maxPeerCount\": 2,\"blockToLive\": 0,\"memberOnlyRead\": true}]"
}

Example Responses

Status code: 400

Bad Request

{
  "error_code" : "BCS.4000013",
  "error_message" : "request body is too large"
}

Status Codes

Status Code

Description

200

Success

400

Bad Request

Error Codes

See Error Codes.