github.com/true-sqn/fabric@v2.1.1+incompatible/docs/source/commands/peerlifecycle.md (about) 1 # peer lifecycle chaincode 2 3 The `peer lifecycle chaincode` subcommand allows administrators to use the 4 Fabric chaincode lifecycle to package a chaincode, install it on your peers, 5 approve a chaincode definition for your organization, and then commit the 6 definition to a channel. The chaincode is ready to be used after the definition 7 has been successfully committed to the channel. For more information, visit 8 [Fabric chaincode lifecycle](../chaincode_lifecycle.html). 9 10 *Note: These instructions use the Fabric chaincode lifecycle introduced in the 11 v2.0 release. If you would like to use the old lifecycle to install and 12 instantiate a chaincode, visit the [peer chaincode](peerchaincode.html) command 13 reference.* 14 15 ## Syntax 16 17 The `peer lifecycle chaincode` command has the following subcommands: 18 19 * package 20 * install 21 * queryinstalled 22 * getinstalledpackage 23 * approveformyorg 24 * checkcommitreadiness 25 * commit 26 * querycommitted 27 28 Each peer lifecycle chaincode subcommand is described together with its options in its own 29 section in this topic. 30 31 ## peer lifecycle 32 ``` 33 Perform _lifecycle operations 34 35 Usage: 36 peer lifecycle [command] 37 38 Available Commands: 39 chaincode Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|approveformyorg|checkcommitreadiness|commit|querycommitted 40 41 Flags: 42 -h, --help help for lifecycle 43 44 Use "peer lifecycle [command] --help" for more information about a command. 45 ``` 46 47 48 ## peer lifecycle chaincode 49 ``` 50 Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|approveformyorg|checkcommitreadiness|commit|querycommitted 51 52 Usage: 53 peer lifecycle chaincode [command] 54 55 Available Commands: 56 approveformyorg Approve the chaincode definition for my org. 57 checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel. 58 commit Commit the chaincode definition on the channel. 59 getinstalledpackage Get an installed chaincode package from a peer. 60 install Install a chaincode. 61 package Package a chaincode 62 querycommitted Query the committed chaincode definitions by channel on a peer. 63 queryinstalled Query the installed chaincodes on a peer. 64 65 Flags: 66 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 67 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 68 --clientauth Use mutual TLS when communicating with the orderer endpoint 69 --connTimeout duration Timeout for client to connect (default 3s) 70 -h, --help help for chaincode 71 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 72 -o, --orderer string Ordering service endpoint 73 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 74 --tls Use TLS when communicating with the orderer endpoint 75 76 Use "peer lifecycle chaincode [command] --help" for more information about a command. 77 ``` 78 79 80 ## peer lifecycle chaincode package 81 ``` 82 Package a chaincode and write the package to a file. 83 84 Usage: 85 peer lifecycle chaincode package [outputfile] [flags] 86 87 Flags: 88 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 89 -h, --help help for package 90 --label string The package label contains a human-readable description of the package 91 -l, --lang string Language the chaincode is written in (default "golang") 92 -p, --path string Path to the chaincode 93 --peerAddresses stringArray The addresses of the peers to connect to 94 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 95 96 Global Flags: 97 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 98 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 99 --clientauth Use mutual TLS when communicating with the orderer endpoint 100 --connTimeout duration Timeout for client to connect (default 3s) 101 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 102 -o, --orderer string Ordering service endpoint 103 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 104 --tls Use TLS when communicating with the orderer endpoint 105 ``` 106 107 108 ## peer lifecycle chaincode install 109 ``` 110 Install a chaincode on a peer. 111 112 Usage: 113 peer lifecycle chaincode install [flags] 114 115 Flags: 116 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 117 -h, --help help for install 118 --peerAddresses stringArray The addresses of the peers to connect to 119 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 120 121 Global Flags: 122 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 123 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 124 --clientauth Use mutual TLS when communicating with the orderer endpoint 125 --connTimeout duration Timeout for client to connect (default 3s) 126 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 127 -o, --orderer string Ordering service endpoint 128 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 129 --tls Use TLS when communicating with the orderer endpoint 130 ``` 131 132 133 ## peer lifecycle chaincode queryinstalled 134 ``` 135 Query the installed chaincodes on a peer. 136 137 Usage: 138 peer lifecycle chaincode queryinstalled [flags] 139 140 Flags: 141 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 142 -h, --help help for queryinstalled 143 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 144 --peerAddresses stringArray The addresses of the peers to connect to 145 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 146 147 Global Flags: 148 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 149 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 150 --clientauth Use mutual TLS when communicating with the orderer endpoint 151 --connTimeout duration Timeout for client to connect (default 3s) 152 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 153 -o, --orderer string Ordering service endpoint 154 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 155 --tls Use TLS when communicating with the orderer endpoint 156 ``` 157 158 159 ## peer lifecycle chaincode getinstalledpackage 160 ``` 161 Get an installed chaincode package from a peer. 162 163 Usage: 164 peer lifecycle chaincode getinstalledpackage [outputfile] [flags] 165 166 Flags: 167 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 168 -h, --help help for getinstalledpackage 169 --output-directory string The output directory to use when writing a chaincode install package to disk. Default is the current working directory. 170 --package-id string The identifier of the chaincode install package 171 --peerAddresses stringArray The addresses of the peers to connect to 172 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 173 174 Global Flags: 175 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 176 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 177 --clientauth Use mutual TLS when communicating with the orderer endpoint 178 --connTimeout duration Timeout for client to connect (default 3s) 179 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 180 -o, --orderer string Ordering service endpoint 181 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 182 --tls Use TLS when communicating with the orderer endpoint 183 ``` 184 185 186 ## peer lifecycle chaincode approveformyorg 187 ``` 188 Approve the chaincode definition for my organization. 189 190 Usage: 191 peer lifecycle chaincode approveformyorg [flags] 192 193 Flags: 194 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 195 -C, --channelID string The channel on which this command should be executed 196 --collections-config string The fully qualified path to the collection JSON file including the file name 197 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 198 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 199 -h, --help help for approveformyorg 200 --init-required Whether the chaincode requires invoking 'init' 201 -n, --name string Name of the chaincode 202 --package-id string The identifier of the chaincode install package 203 --peerAddresses stringArray The addresses of the peers to connect to 204 --sequence int The sequence number of the chaincode definition for the channel (default 1) 205 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 206 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 207 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 208 -v, --version string Version of the chaincode 209 --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) 210 --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) 211 212 Global Flags: 213 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 214 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 215 --clientauth Use mutual TLS when communicating with the orderer endpoint 216 --connTimeout duration Timeout for client to connect (default 3s) 217 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 218 -o, --orderer string Ordering service endpoint 219 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 220 --tls Use TLS when communicating with the orderer endpoint 221 ``` 222 223 224 ## peer lifecycle chaincode checkcommitreadiness 225 ``` 226 Check whether a chaincode definition is ready to be committed on a channel. 227 228 Usage: 229 peer lifecycle chaincode checkcommitreadiness [flags] 230 231 Flags: 232 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 233 -C, --channelID string The channel on which this command should be executed 234 --collections-config string The fully qualified path to the collection JSON file including the file name 235 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 236 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 237 -h, --help help for checkcommitreadiness 238 --init-required Whether the chaincode requires invoking 'init' 239 -n, --name string Name of the chaincode 240 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 241 --peerAddresses stringArray The addresses of the peers to connect to 242 --sequence int The sequence number of the chaincode definition for the channel (default 1) 243 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 244 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 245 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 246 -v, --version string Version of the chaincode 247 248 Global Flags: 249 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 250 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 251 --clientauth Use mutual TLS when communicating with the orderer endpoint 252 --connTimeout duration Timeout for client to connect (default 3s) 253 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 254 -o, --orderer string Ordering service endpoint 255 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 256 --tls Use TLS when communicating with the orderer endpoint 257 ``` 258 259 260 ## peer lifecycle chaincode commit 261 ``` 262 Commit the chaincode definition on the channel. 263 264 Usage: 265 peer lifecycle chaincode commit [flags] 266 267 Flags: 268 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 269 -C, --channelID string The channel on which this command should be executed 270 --collections-config string The fully qualified path to the collection JSON file including the file name 271 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 272 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 273 -h, --help help for commit 274 --init-required Whether the chaincode requires invoking 'init' 275 -n, --name string Name of the chaincode 276 --peerAddresses stringArray The addresses of the peers to connect to 277 --sequence int The sequence number of the chaincode definition for the channel (default 1) 278 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 279 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 280 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 281 -v, --version string Version of the chaincode 282 --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) 283 --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) 284 285 Global Flags: 286 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 287 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 288 --clientauth Use mutual TLS when communicating with the orderer endpoint 289 --connTimeout duration Timeout for client to connect (default 3s) 290 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 291 -o, --orderer string Ordering service endpoint 292 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 293 --tls Use TLS when communicating with the orderer endpoint 294 ``` 295 296 297 ## peer lifecycle chaincode querycommitted 298 ``` 299 Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. 300 301 Usage: 302 peer lifecycle chaincode querycommitted [flags] 303 304 Flags: 305 -C, --channelID string The channel on which this command should be executed 306 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 307 -h, --help help for querycommitted 308 -n, --name string Name of the chaincode 309 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 310 --peerAddresses stringArray The addresses of the peers to connect to 311 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 312 313 Global Flags: 314 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 315 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 316 --clientauth Use mutual TLS when communicating with the orderer endpoint 317 --connTimeout duration Timeout for client to connect (default 3s) 318 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 319 -o, --orderer string Ordering service endpoint 320 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. 321 --tls Use TLS when communicating with the orderer endpoint 322 ``` 323 324 325 ## Example Usage 326 327 ### peer lifecycle chaincode package example 328 329 A chaincode needs to be packaged before it can be installed on your peers. 330 This example uses the `peer lifecycle chaincode package` command to package 331 a Go chaincode. 332 333 * Use the `--label` flag to provide a chaincode package label of `myccv1` 334 that your organization will use to identify the package. 335 336 ``` 337 peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label myccv1 338 ``` 339 340 ### peer lifecycle chaincode install example 341 342 After the chaincode is packaged, you can use the `peer chaincode install` command 343 to install the chaincode on your peers. 344 345 * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the 346 peer defined by `--peerAddresses`). 347 348 ``` 349 peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 350 ``` 351 If successful, the command will return the package identifier. The 352 package ID is the package label combined with a hash of the chaincode 353 package taken by the peer. 354 ``` 355 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" > 356 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 357 ``` 358 359 ### peer lifecycle chaincode queryinstalled example 360 361 You need to use the chaincode package identifier to approve a chaincode 362 definition for your organization. You can find the package ID for the 363 chaincodes you have installed by using the 364 `peer lifecycle chaincode queryinstalled` command: 365 366 ``` 367 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 368 ``` 369 370 A successful command will return the package ID associated with the 371 package label. 372 373 ``` 374 Get installed chaincodes on peer: 375 Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 376 ``` 377 378 * You can also use the `--output` flag to have the CLI format the output as 379 JSON. 380 381 ``` 382 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json 383 ``` 384 385 If successful, the command will return the chaincodes you have installed as JSON. 386 387 ``` 388 { 389 "installed_chaincodes": [ 390 { 391 "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b", 392 "label": "mycc_1", 393 "references": { 394 "mychannel": { 395 "chaincodes": [ 396 { 397 "name": "mycc", 398 "version": "1" 399 } 400 ] 401 } 402 } 403 } 404 ] 405 } 406 ``` 407 408 ### peer lifecycle chaincode getinstalledpackage example 409 410 You can retrieve an installed chaincode package from a peer using the 411 `peer lifecycle chaincode getinstalledpackage` command. Use the package 412 identifier returned by `queryinstalled`. 413 414 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 415 the `--output-directory` flag to specify where to write the chaincode package. 416 If the output directory is not specified, the chaincode package will be written 417 in the current directory. 418 419 ``` 420 peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 421 ``` 422 423 424 ### peer lifecycle chaincode approveformyorg example 425 426 Once the chaincode package has been installed on your peers, you can approve 427 a chaincode definition for your organization. The chaincode definition includes 428 the important parameters of chaincode governance, including the chaincode name, 429 version and the endorsement policy. 430 431 Here is an example of the `peer lifecycle chaincode approveformyorg` command, 432 which approves the definition of a chaincode named `mycc` at version `1.0` on 433 channel `mychannel`. 434 435 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 436 the `--signature-policy` flag to define an endorsement policy for the chaincode. 437 Use the `init-required` flag to request the execution of the `Init` 438 function to initialize the chaincode. 439 440 ``` 441 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 442 443 peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" 444 445 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 446 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 447 ``` 448 449 * You can also use the `--channel-config-policy` flag use a policy inside 450 the channel configuration as the chaincode endorsement policy. The default 451 endorsement policy is `Channel/Application/Endorsement` 452 453 ``` 454 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 455 456 peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --channel-config-policy Channel/Application/Admins 457 458 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 459 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 460 ``` 461 462 ### peer lifecycle chaincode checkcommitreadiness example 463 464 You can check whether a chaincode definition is ready to be committed using the 465 `peer lifecycle chaincode checkcommitreadiness` command, which will return 466 successfully if a subsequent commit of the definition is expected to succeed. It 467 also outputs which organizations have approved the chaincode definition. If an 468 organization has approved the chaincode definition specified in the command, the 469 command will return a value of true. You can use this command to learn whether enough 470 channel members have approved a chaincode definition to meet the 471 `Application/Channel/Endorsement` policy (a majority by default) before the 472 definition can be committed to a channel. 473 474 * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command, 475 which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. 476 477 ``` 478 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 479 480 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 481 ``` 482 483 If successful, the command will return the organizations that have approved 484 the chaincode definition. 485 486 ``` 487 Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel 488 'mychannel' approval status by org: 489 Org1MSP: true 490 Org2MSP: true 491 ``` 492 493 * You can also use the `--output` flag to have the CLI format the output as 494 JSON. 495 496 ``` 497 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 498 499 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 --output json 500 ``` 501 502 If successful, the command will return a JSON map that shows if an organization 503 has approved the chaincode definition. 504 505 ``` 506 { 507 "Approvals": { 508 "Org1MSP": true, 509 "Org2MSP": true 510 } 511 } 512 ``` 513 514 ### peer lifecycle chaincode commit example 515 516 Once a sufficient number of organizations approve a chaincode definition for 517 their organizations (a majority by default), one organization can commit the 518 definition the channel using the `peer lifecycle chaincode commit` command: 519 520 * This command needs to target the peers of other organizations on the channel 521 to collect their organization endorsement for the definition. 522 523 ``` 524 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 525 526 peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 527 528 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 529 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 530 ``` 531 532 ### peer lifecycle chaincode querycommitted example 533 534 You can query the chaincode definitions that have been committed to a channel by 535 using the `peer lifecycle chaincode querycommitted` command. You can use this 536 command to query the current definition sequence number before upgrading a 537 chaincode. 538 539 * You need to supply the chaincode name and channel name in order to query a 540 specific chaincode definition and the organizations that have approved it. 541 542 ``` 543 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 544 545 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 546 547 Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': 548 Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 549 Approvals: [Org1MSP: true, Org2MSP: true] 550 ``` 551 552 * You can also specify just the channel name in order to query all chaincode 553 definitions on that channel. 554 555 ``` 556 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 557 558 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 559 560 Committed chaincode definitions on channel 'mychannel': 561 Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 562 Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc 563 ``` 564 565 * You can also use the `--output` flag to have the CLI format the output as 566 JSON. 567 568 - For querying a specific chaincode definition 569 570 ``` 571 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 572 573 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 574 ``` 575 576 If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. 577 578 ``` 579 { 580 "sequence": 1, 581 "version": "1", 582 "endorsement_plugin": "escc", 583 "validation_plugin": "vscc", 584 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 585 "collections": {}, 586 "init_required": true, 587 "approvals": { 588 "Org1MSP": true, 589 "Org2MSP": true 590 } 591 } 592 ``` 593 594 The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. 595 596 ``` 597 echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d 598 599 /Channel/Application/Endorsement 600 ``` 601 602 - For querying all chaincode definitions on that channel 603 604 ``` 605 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 606 607 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 608 ``` 609 610 If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. 611 612 ``` 613 { 614 "chaincode_definitions": [ 615 { 616 "name": "mycc", 617 "sequence": 1, 618 "version": "1", 619 "endorsement_plugin": "escc", 620 "validation_plugin": "vscc", 621 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 622 "collections": {}, 623 "init_required": true 624 }, 625 { 626 "name": "yourcc", 627 "sequence": 3, 628 "version": "2", 629 "endorsement_plugin": "escc", 630 "validation_plugin": "vscc", 631 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 632 "collections": {} 633 } 634 ] 635 } 636 ``` 637 638 639 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.