peer lifecycle chaincode

The peer lifecycle chaincode subcommand allows administrators to use the Fabric chaincode lifecycle to package a chaincode, install it on your peers, approve a chaincode definition for your organization, and then commit the definition to a channel. The chaincode is ready to be used after the definition has been successfully committed to the channel. For more information, visit Fabric chaincode lifecycle.

Note: These instructions use the Fabric chaincode lifecycle introduced in the v2.0 release. If you would like to use the old lifecycle to install and instantiate a chaincode, visit the peer chaincode command reference.

Syntax

The peer lifecycle chaincode command has the following subcommands:

  • package

  • install

  • queryinstalled

  • getinstalledpackage

  • calculatepackageid

  • approveformyorg

  • queryapproved

  • checkcommitreadiness

  • commit

  • querycommitted

Each peer lifecycle chaincode subcommand is described together with its options in its own section in this topic.

peer lifecycle

  1. Perform _lifecycle operations
  2. Usage:
  3. peer lifecycle [command]
  4. Available Commands:
  5. chaincode Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted
  6. Flags:
  7. -h, --help help for lifecycle
  8. Use "peer lifecycle [command] --help" for more information about a command.

peer lifecycle chaincode

  1. Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|calculatepackageid|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted
  2. Usage:
  3. peer lifecycle chaincode [command]
  4. Available Commands:
  5. approveformyorg Approve the chaincode definition for my org.
  6. calculatepackageid Calculate the package ID for a chaincode.
  7. checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel.
  8. commit Commit the chaincode definition on the channel.
  9. getinstalledpackage Get an installed chaincode package from a peer.
  10. install Install a chaincode.
  11. package Package a chaincode
  12. queryapproved Query an org's approved chaincode definition from its peer.
  13. querycommitted Query the committed chaincode definitions by channel on a peer.
  14. queryinstalled Query the installed chaincodes on a peer.
  15. Flags:
  16. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  17. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  18. --clientauth Use mutual TLS when communicating with the orderer endpoint
  19. --connTimeout duration Timeout for client to connect (default 3s)
  20. -h, --help help for chaincode
  21. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  22. -o, --orderer string Ordering service endpoint
  23. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  24. --tls Use TLS when communicating with the orderer endpoint
  25. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  26. Use "peer lifecycle chaincode [command] --help" for more information about a command.

peer lifecycle chaincode package

  1. Package a chaincode and write the package to a file.
  2. Usage:
  3. peer lifecycle chaincode package [outputfile] [flags]
  4. Flags:
  5. --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
  6. -h, --help help for package
  7. --label string The package label contains a human-readable description of the package
  8. -l, --lang string Language the chaincode is written in (default "golang")
  9. -p, --path string Path to the chaincode
  10. --peerAddresses stringArray The addresses of the peers to connect to
  11. --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
  12. Global Flags:
  13. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  14. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  15. --clientauth Use mutual TLS when communicating with the orderer endpoint
  16. --connTimeout duration Timeout for client to connect (default 3s)
  17. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  18. -o, --orderer string Ordering service endpoint
  19. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  20. --tls Use TLS when communicating with the orderer endpoint
  21. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode install

  1. Install a chaincode on a peer.
  2. Usage:
  3. peer lifecycle chaincode install [flags]
  4. Flags:
  5. --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
  6. -h, --help help for install
  7. --peerAddresses stringArray The addresses of the peers to connect to
  8. --targetPeer string When using a connection profile, the name of the peer to target for this action
  9. --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
  10. Global Flags:
  11. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  12. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  13. --clientauth Use mutual TLS when communicating with the orderer endpoint
  14. --connTimeout duration Timeout for client to connect (default 3s)
  15. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  16. -o, --orderer string Ordering service endpoint
  17. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  18. --tls Use TLS when communicating with the orderer endpoint
  19. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode queryinstalled

  1. Query the installed chaincodes on a peer.
  2. Usage:
  3. peer lifecycle chaincode queryinstalled [flags]
  4. Flags:
  5. --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
  6. -h, --help help for queryinstalled
  7. -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format.
  8. --peerAddresses stringArray The addresses of the peers to connect to
  9. --targetPeer string When using a connection profile, the name of the peer to target for this action
  10. --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
  11. Global Flags:
  12. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  13. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  14. --clientauth Use mutual TLS when communicating with the orderer endpoint
  15. --connTimeout duration Timeout for client to connect (default 3s)
  16. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  17. -o, --orderer string Ordering service endpoint
  18. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  19. --tls Use TLS when communicating with the orderer endpoint
  20. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode getinstalledpackage

  1. Get an installed chaincode package from a peer.
  2. Usage:
  3. peer lifecycle chaincode getinstalledpackage [outputfile] [flags]
  4. Flags:
  5. --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
  6. -h, --help help for getinstalledpackage
  7. --output-directory string The output directory to use when writing a chaincode install package to disk. Default is the current working directory.
  8. --package-id string The identifier of the chaincode install package
  9. --peerAddresses stringArray The addresses of the peers to connect to
  10. --targetPeer string When using a connection profile, the name of the peer to target for this action
  11. --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
  12. Global Flags:
  13. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  14. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  15. --clientauth Use mutual TLS when communicating with the orderer endpoint
  16. --connTimeout duration Timeout for client to connect (default 3s)
  17. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  18. -o, --orderer string Ordering service endpoint
  19. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  20. --tls Use TLS when communicating with the orderer endpoint
  21. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode calculatepackageid

  1. Calculate the package ID for a packaged chaincode.
  2. Usage:
  3. peer lifecycle chaincode calculatepackageid packageFile [flags]
  4. Flags:
  5. --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
  6. -h, --help help for calculatepackageid
  7. -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format.
  8. --peerAddresses stringArray The addresses of the peers to connect to
  9. --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
  10. Global Flags:
  11. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  12. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  13. --clientauth Use mutual TLS when communicating with the orderer endpoint
  14. --connTimeout duration Timeout for client to connect (default 3s)
  15. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  16. -o, --orderer string Ordering service endpoint
  17. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  18. --tls Use TLS when communicating with the orderer endpoint
  19. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode approveformyorg

  1. Approve the chaincode definition for my organization.
  2. Usage:
  3. peer lifecycle chaincode approveformyorg [flags]
  4. Flags:
  5. --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference
  6. -C, --channelID string The channel on which this command should be executed
  7. --collections-config string The fully qualified path to the collection JSON file including the file name
  8. --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
  9. -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode
  10. -h, --help help for approveformyorg
  11. --init-required Whether the chaincode requires invoking 'init'
  12. -n, --name string Name of the chaincode
  13. --package-id string The identifier of the chaincode install package
  14. --peerAddresses stringArray The addresses of the peers to connect to
  15. --sequence int The sequence number of the chaincode definition for the channel
  16. --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy
  17. --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
  18. -V, --validation-plugin string The name of the validation plugin to be used for this chaincode
  19. -v, --version string Version of the chaincode
  20. --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true)
  21. --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)
  22. Global Flags:
  23. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  24. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  25. --clientauth Use mutual TLS when communicating with the orderer endpoint
  26. --connTimeout duration Timeout for client to connect (default 3s)
  27. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  28. -o, --orderer string Ordering service endpoint
  29. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  30. --tls Use TLS when communicating with the orderer endpoint
  31. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode queryapproved

  1. Query an organization's approved chaincode definition from its peer.
  2. Usage:
  3. peer lifecycle chaincode queryapproved [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --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
  7. -h, --help help for queryapproved
  8. -n, --name string Name of the chaincode
  9. -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format.
  10. --peerAddresses stringArray The addresses of the peers to connect to
  11. --sequence int The sequence number of the chaincode definition for the channel
  12. --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
  13. Global Flags:
  14. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  15. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  16. --clientauth Use mutual TLS when communicating with the orderer endpoint
  17. --connTimeout duration Timeout for client to connect (default 3s)
  18. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  19. -o, --orderer string Ordering service endpoint
  20. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  21. --tls Use TLS when communicating with the orderer endpoint
  22. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode checkcommitreadiness

  1. Check whether a chaincode definition is ready to be committed on a channel.
  2. Usage:
  3. peer lifecycle chaincode checkcommitreadiness [flags]
  4. Flags:
  5. --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference
  6. -C, --channelID string The channel on which this command should be executed
  7. --collections-config string The fully qualified path to the collection JSON file including the file name
  8. --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
  9. -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode
  10. -h, --help help for checkcommitreadiness
  11. --init-required Whether the chaincode requires invoking 'init'
  12. -n, --name string Name of the chaincode
  13. -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format.
  14. --peerAddresses stringArray The addresses of the peers to connect to
  15. --sequence int The sequence number of the chaincode definition for the channel
  16. --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy
  17. --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
  18. -V, --validation-plugin string The name of the validation plugin to be used for this chaincode
  19. -v, --version string Version of the chaincode
  20. Global Flags:
  21. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  22. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  23. --clientauth Use mutual TLS when communicating with the orderer endpoint
  24. --connTimeout duration Timeout for client to connect (default 3s)
  25. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  26. -o, --orderer string Ordering service endpoint
  27. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  28. --tls Use TLS when communicating with the orderer endpoint
  29. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode commit

  1. Commit the chaincode definition on the channel.
  2. Usage:
  3. peer lifecycle chaincode commit [flags]
  4. Flags:
  5. --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference
  6. -C, --channelID string The channel on which this command should be executed
  7. --collections-config string The fully qualified path to the collection JSON file including the file name
  8. --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
  9. -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode
  10. -h, --help help for commit
  11. --init-required Whether the chaincode requires invoking 'init'
  12. -n, --name string Name of the chaincode
  13. --peerAddresses stringArray The addresses of the peers to connect to
  14. --sequence int The sequence number of the chaincode definition for the channel
  15. --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy
  16. --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
  17. -V, --validation-plugin string The name of the validation plugin to be used for this chaincode
  18. -v, --version string Version of the chaincode
  19. --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true)
  20. --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)
  21. Global Flags:
  22. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  23. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  24. --clientauth Use mutual TLS when communicating with the orderer endpoint
  25. --connTimeout duration Timeout for client to connect (default 3s)
  26. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  27. -o, --orderer string Ordering service endpoint
  28. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  29. --tls Use TLS when communicating with the orderer endpoint
  30. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

peer lifecycle chaincode querycommitted

  1. Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition.
  2. Usage:
  3. peer lifecycle chaincode querycommitted [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --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
  7. -h, --help help for querycommitted
  8. -n, --name string Name of the chaincode
  9. -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format.
  10. --peerAddresses stringArray The addresses of the peers to connect to
  11. --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
  12. Global Flags:
  13. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  14. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  15. --clientauth Use mutual TLS when communicating with the orderer endpoint
  16. --connTimeout duration Timeout for client to connect (default 3s)
  17. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  18. -o, --orderer string Ordering service endpoint
  19. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  20. --tls Use TLS when communicating with the orderer endpoint
  21. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint

Example Usage

peer lifecycle chaincode package example

A chaincode needs to be packaged before it can be installed on your peers. This example uses the peer lifecycle chaincode package command to package a Go chaincode.

  • Use the --path flag to indicate the location of the chaincode. The path must be a fully qualified path or a path relative to your present working directory.

  • Use the --label flag to provide a chaincode package label of myccv1 that your organization will use to identify the package.

    1. peer lifecycle chaincode package mycc.tar.gz --path $CHAINCODE_DIR --lang golang --label myccv1

peer lifecycle chaincode install example

After the chaincode is packaged, you can use the peer chaincode install command to install the chaincode on your peers.

  • Install the mycc.tar.gz package on peer0.org1.example.com:7051 (the peer defined by --peerAddresses).

    1. peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051

    If successful, the command will return the package identifier. The package ID is the package label combined with a hash of the chaincode package taken by the peer.

    1. 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" >
    2. 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9

peer lifecycle chaincode queryinstalled example

You need to use the chaincode package identifier to approve a chaincode definition for your organization. You can find the package ID for the chaincodes you have installed by using the peer lifecycle chaincode queryinstalled command:

  1. peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051

A successful command will return the package ID associated with the package label.

  1. Get installed chaincodes on peer:
  2. Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1
  • You can also use the --output flag to have the CLI format the output as JSON.

    1. peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json

    If successful, the command will return the chaincodes you have installed as JSON.

    1. {
    2. "installed_chaincodes": [
    3. {
    4. "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b",
    5. "label": "mycc_1",
    6. "references": {
    7. "mychannel": {
    8. "chaincodes": [
    9. {
    10. "name": "mycc",
    11. "version": "1"
    12. }
    13. ]
    14. }
    15. }
    16. }
    17. ]
    18. }

peer lifecycle chaincode getinstalledpackage example

You can retrieve an installed chaincode package from a peer using the peer lifecycle chaincode getinstalledpackage command. Use the package identifier returned by queryinstalled.

  • Use the --package-id flag to pass in the chaincode package identifier. Use the --output-directory flag to specify where to write the chaincode package. If the output directory is not specified, the chaincode package will be written in the current directory.
  1. peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051

peer lifecycle chaincode calculatepackageid example

You can calculate the package ID from a packaged chaincode without installing the chaincode on peers using the peer lifecycle chaincode calculatepackageid command. This command will be useful, for example, in the following cases:

  • When multiple chaincode packages with the same label name are installed, it is possible to identify which ID corresponds to which package later.

  • To check whether a particular chaincode package is installed or not without installing that package.

Calculate the package ID for the mycc.tar.gz package:

  1. peer lifecycle chaincode calculatepackageid mycc.tar.gz

A successful command will return the package ID for the packaged chaincode.

  1. myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873
  • You can also use the --output flag to have the CLI format the output as JSON.

    1. peer lifecycle chaincode calculatepackageid mycc.tar.gz --output json

    If successful, the command will return the chaincode package ID as JSON.

    1. {
    2. "package_id": "myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873"
    3. }

peer lifecycle chaincode approveformyorg example

Once the chaincode package has been installed on your peers, you can approve a chaincode definition for your organization. The chaincode definition includes the important parameters of chaincode governance, including the chaincode name, version and the endorsement policy.

Here is an example of the peer lifecycle chaincode approveformyorg command, which approves the definition of a chaincode named mycc at version 1.0 on channel mychannel.

  • Use the --package-id flag to pass in the chaincode package identifier. Use the --signature-policy flag to define an endorsement policy for the chaincode. Use the init-required flag to require the execution of an initialization function before other chaincode functions can be called.

    1. 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
    2. 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')"
    3. 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
    4. 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051
  • You can also use the --channel-config-policy flag use a policy inside the channel configuration as the chaincode endorsement policy. The default endorsement policy is Channel/Application/Endorsement

    1. 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
    2. 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
    3. 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
    4. 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051

peer lifecycle chaincode queryapproved example

You can query an organization’s approved chaincode definition by using the peer lifecycle chaincode queryapproved command. You can use this command to see the details (including package ID) of approved chaincode definitions.

  • Here is an example of the peer lifecycle chaincode queryapproved command, which queries the approved definition of a chaincode named mycc at sequence number 1 on channel mychannel.

    1. peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1
    2. Approved chaincode definition for chaincode 'mycc' on channel 'mychannel':
    3. sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc

    If NO package is specified for the approved definition, this command will display an empty package ID.

  • You can also use this command without specifying the sequence number in order to query the latest approved definition (latest: the newer of the currently defined sequence number and the next sequence number).

    1. peer lifecycle chaincode queryapproved -C mychannel -n mycc
    2. Approved chaincode definition for chaincode 'mycc' on channel 'mychannel':
    3. sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc
  • You can also use the --output flag to have the CLI format the output as JSON.

    • When querying an approved chaincode definition for which package is specified

      1. peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json

      If successful, the command will return a JSON that has the approved chaincode definition for chaincode mycc at sequence number 1 on channel mychannel.

      1. {
      2. "sequence": 1,
      3. "version": "1",
      4. "endorsement_plugin": "escc",
      5. "validation_plugin": "vscc",
      6. "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
      7. "collections": {},
      8. "init_required": true,
      9. "source": {
      10. "Type": {
      11. "LocalPackage": {
      12. "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830"
      13. }
      14. }
      15. }
      16. }
    • When querying an approved chaincode definition for which package is NOT specified

      1. peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json

      If successful, the command will return a JSON that has the approved chaincode definition for chaincode mycc at sequence number 2 on channel mychannel.

      1. {
      2. "sequence": 2,
      3. "version": "2",
      4. "endorsement_plugin": "escc",
      5. "validation_plugin": "vscc",
      6. "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
      7. "collections": {},
      8. "source": {
      9. "Type": {
      10. "Unavailable": {}
      11. }
      12. }
      13. }

peer lifecycle chaincode checkcommitreadiness example

You can check whether a chaincode definition is ready to be committed using the peer lifecycle chaincode checkcommitreadiness command, which will return successfully if a subsequent commit of the definition is expected to succeed. It also outputs which organizations have approved the chaincode definition. If an organization has approved the chaincode definition specified in the command, the command will return a value of true. You can use this command to learn whether enough channel members have approved a chaincode definition to meet the /Channel/Application/Endorsement policy (a majority by default) before the definition can be committed to a channel.

  • Here is an example of the peer lifecycle chaincode checkcommitreadiness command, which checks a chaincode named mycc at version 1.0 on channel mychannel.

    1. 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
    2. peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1

    If successful, the command will return the organizations that have approved the chaincode definition.

    1. Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel
    2. 'mychannel' approval status by org:
    3. Org1MSP: true
    4. Org2MSP: true
  • You can also use the --output flag to have the CLI format the output as JSON.

    1. 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
    2. 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

    If successful, the command will return a JSON map that shows if an organization has approved the chaincode definition.

    1. {
    2. "Approvals": {
    3. "Org1MSP": true,
    4. "Org2MSP": true
    5. }
    6. }

peer lifecycle chaincode commit example

Once a sufficient number of organizations approve a chaincode definition for their organizations (a majority by default), one organization can commit the definition the channel using the peer lifecycle chaincode commit command:

  • This command needs to target the peers of other organizations on the channel to collect their organization endorsement for the definition.

    1. 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
    2. 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
    3. 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051
    4. 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051

peer lifecycle chaincode querycommitted example

You can query the chaincode definitions that have been committed to a channel by using the peer lifecycle chaincode querycommitted command. You can use this command to query the current definition sequence number before upgrading a chaincode.

  • You need to supply the chaincode name and channel name in order to query a specific chaincode definition and the organizations that have approved it.

    1. 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
    2. peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
    3. Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
    4. Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
    5. Approvals: [Org1MSP: true, Org2MSP: true]
  • You can also specify just the channel name in order to query all chaincode definitions on that channel.

    1. 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
    2. peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
    3. Committed chaincode definitions on channel 'mychannel':
    4. Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
    5. Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc
  • You can also use the --output flag to have the CLI format the output as JSON.

    • For querying a specific chaincode definition

      1. 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
      2. 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

      If successful, the command will return a JSON that has committed chaincode definition for chaincode ‘mycc’ on channel ‘mychannel’.

      1. {
      2. "sequence": 1,
      3. "version": "1",
      4. "endorsement_plugin": "escc",
      5. "validation_plugin": "vscc",
      6. "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
      7. "collections": {},
      8. "init_required": true,
      9. "approvals": {
      10. "Org1MSP": true,
      11. "Org2MSP": true
      12. }
      13. }

      The validation_parameter is base64 encoded. An example of the command to decode it is as follows.

      1. echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d
      2. /Channel/Application/Endorsement
    • For querying all chaincode definitions on that channel

      1. 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
      2. peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json

      If successful, the command will return a JSON that has committed chaincode definitions on channel ‘mychannel’.

      1. {
      2. "chaincode_definitions": [
      3. {
      4. "name": "mycc",
      5. "sequence": 1,
      6. "version": "1",
      7. "endorsement_plugin": "escc",
      8. "validation_plugin": "vscc",
      9. "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
      10. "collections": {},
      11. "init_required": true
      12. },
      13. {
      14. "name": "yourcc",
      15. "sequence": 3,
      16. "version": "2",
      17. "endorsement_plugin": "escc",
      18. "validation_plugin": "vscc",
      19. "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
      20. "collections": {}
      21. }
      22. ]
      23. }

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.