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

Installing a Chaincode

Function

This API is used to install a chaincode on blockchain nodes. In some scenarios, only Go chaincodes are supported.

URI

POST /v2/agent/apis/chaincode/install

Request Parameters

Table 1 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Table 2 FormData parameters

Parameter

Mandatory

Type

Description

chaincode_name

Yes

String

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

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.

Minimum: 1

Maximum: 14

target_peers

Yes

String

List of peers where the chaincode is installed, for example, [{"org_id":"9fb42c91458763990a45b62af92546a21f168dae","org_name":"organization3","peer_id":"peer-9fb42c91458763990a45b62af92546a21f168dae-0.peer-9fb42c91458763990a45b62af92546a21f168dae.default.svc.cluster.local","peer_name":"peer-0"}].

description

No

String

Chaincode description.

chaincode_language

Yes

String

Programming language of the chaincode, for example, Go.

db_type

No

String

Database type used by the chaincode. Set this parameter based on the ledger data storage mode set during instance creation. Example: goleveldb or couchdb.

security_check

No

String

Chaincode security check option. This parameter is valid only for Golang chaincodes. The value true indicates that the function is enabled, and the value false indicates that the function is disabled. The default value is false.

file

Yes

File

Chaincode ZIP file.

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

total_peer_num

Integer

Total number of peers where the chaincode is installed.

success_peer_num

Integer

Number of peers where the chaincode is installed successfully.

fail_peer_num

Integer

Number of peers where the chaincode fails to be installed.

fail_peers

Array of strings

Details of peers where the chaincode fails to be installed.

Status code: 400

Table 4 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/install

{chaincode_name:gochaincode3chaincode_version:2.0target_peers:[{"org_id":"9802af57cfab764dc12b860c44b01969575e83c9","org_name":"organization","peer_id":"peer-9802af57cfab764dc12b860c44b01969575e83c9-1.peer-9802af57cfab764dc12b860c44b01969575e83c9.default.svc.cluster.local","peer_name":"node-1"}]description:22222222chaincode_language:golangdb_type:goleveldbsecurity_check:true}

Example Responses

Status code: 200

Success

{
  "total_peer_num" : 4,
  "success_peer_num" : 4,
  "fail_peer_num" : 0,
  "fail_peers" : [ ]
}

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.