github.com/kaituanwang/hyperledger@v2.0.1+incompatible/docs/source/commands/peerchaincode.md (about)

     1  # peer chaincode
     2  
     3  The `peer chaincode` command allows administrators to perform chaincode
     4  related operations on a peer, such as installing, instantiating, invoking,
     5  packaging, querying, and upgrading chaincode.
     6  
     7  ## Syntax
     8  
     9  The `peer chaincode` command has the following subcommands:
    10  
    11    * install
    12    * instantiate
    13    * invoke
    14    * list
    15    * package
    16    * query
    17    * signpackage
    18    * upgrade
    19  
    20  The different subcommand options (install, instantiate...) relate to the
    21  different chaincode operations that are relevant to a peer. For example, use the
    22  `peer chaincode install` subcommand option to install a chaincode on a peer, or
    23  the `peer chaincode query` subcommand option to query a chaincode for the
    24  current value on a peer's ledger.
    25  
    26  Each peer chaincode subcommand is described together with its options in its own
    27  section in this topic.
    28  
    29  ## Flags
    30  
    31  Each `peer chaincode` subcommand has both a set of flags specific to an
    32  individual subcommand, as well as a set of global flags that relate to all
    33  `peer chaincode` subcommands. Not all subcommands would use these flags.
    34  For instance, the `query` subcommand does not need the `--orderer` flag.
    35  
    36  The individual flags are described with the relevant subcommand. The global
    37  flags are
    38  
    39  * `--cafile <string>`
    40  
    41    Path to file containing PEM-encoded trusted certificate(s) for the ordering
    42    endpoint
    43  
    44  * `--certfile <string>`
    45  
    46    Path to file containing PEM-encoded X509 public key to use for mutual TLS
    47    communication with the orderer endpoint
    48  
    49  * `--keyfile <string>`
    50  
    51    Path to file containing PEM-encoded private key to use for mutual TLS
    52    communication with the orderer endpoint
    53  
    54  * `-o` or `--orderer <string>`
    55  
    56    Ordering service endpoint specified as `<hostname or IP address>:<port>`
    57  
    58  * `--ordererTLSHostnameOverride <string>`
    59  
    60    The hostname override to use when validating the TLS connection to the orderer
    61  
    62  * `--tls`
    63  
    64    Use TLS when communicating with the orderer endpoint
    65  
    66  * `--transient <string>`
    67  
    68    Transient map of arguments in JSON encoding
    69  
    70  ## peer chaincode install
    71  ```
    72  Install a chaincode on a peer. This installs a chaincode deployment spec package (if provided) or packages the specified chaincode before subsequently installing it.
    73  
    74  Usage:
    75    peer chaincode install [flags]
    76  
    77  Flags:
    78        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
    79    -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
    80    -h, --help                           help for install
    81    -l, --lang string                    Language the chaincode is written in (default "golang")
    82    -n, --name string                    Name of the chaincode
    83    -p, --path string                    Path to chaincode
    84        --peerAddresses stringArray      The addresses of the peers to connect to
    85        --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
    86    -v, --version string                 Version of the chaincode specified in install/instantiate/upgrade commands
    87  
    88  Global Flags:
    89        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
    90        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
    91        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
    92        --connTimeout duration                Timeout for client to connect (default 3s)
    93        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
    94    -o, --orderer string                      Ordering service endpoint
    95        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
    96        --tls                                 Use TLS when communicating with the orderer endpoint
    97        --transient string                    Transient map of arguments in JSON encoding
    98  ```
    99  
   100  
   101  ## peer chaincode instantiate
   102  ```
   103  Deploy the specified chaincode to the network.
   104  
   105  Usage:
   106    peer chaincode instantiate [flags]
   107  
   108  Flags:
   109    -C, --channelID string               The channel on which this command should be executed
   110        --collections-config string      The fully qualified path to the collection JSON file including the file name
   111        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
   112    -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
   113    -E, --escc string                    The name of the endorsement system chaincode to be used for this chaincode
   114    -h, --help                           help for instantiate
   115    -l, --lang string                    Language the chaincode is written in (default "golang")
   116    -n, --name string                    Name of the chaincode
   117        --peerAddresses stringArray      The addresses of the peers to connect to
   118    -P, --policy string                  The endorsement policy associated to this chaincode
   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    -v, --version string                 Version of the chaincode specified in install/instantiate/upgrade commands
   121    -V, --vscc string                    The name of the verification system chaincode to be used for this chaincode
   122  
   123  Global Flags:
   124        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   125        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   126        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   127        --connTimeout duration                Timeout for client to connect (default 3s)
   128        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   129    -o, --orderer string                      Ordering service endpoint
   130        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   131        --tls                                 Use TLS when communicating with the orderer endpoint
   132        --transient string                    Transient map of arguments in JSON encoding
   133  ```
   134  
   135  
   136  ## peer chaincode invoke
   137  ```
   138  Invoke the specified chaincode. It will try to commit the endorsed transaction to the network.
   139  
   140  Usage:
   141    peer chaincode invoke [flags]
   142  
   143  Flags:
   144    -C, --channelID string               The channel on which this command should be executed
   145        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
   146    -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
   147    -h, --help                           help for invoke
   148    -I, --isInit                         Is this invocation for init (useful for supporting legacy chaincodes in the new lifecycle)
   149    -n, --name string                    Name of the chaincode
   150        --peerAddresses stringArray      The addresses of the peers to connect to
   151        --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
   152        --waitForEvent                   Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully
   153        --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)
   154  
   155  Global Flags:
   156        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   157        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   158        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   159        --connTimeout duration                Timeout for client to connect (default 3s)
   160        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   161    -o, --orderer string                      Ordering service endpoint
   162        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   163        --tls                                 Use TLS when communicating with the orderer endpoint
   164        --transient string                    Transient map of arguments in JSON encoding
   165  ```
   166  
   167  
   168  ## peer chaincode list
   169  ```
   170  Get the instantiated chaincodes in the channel if specify channel, or get installed chaincodes on the peer
   171  
   172  Usage:
   173    peer chaincode list [flags]
   174  
   175  Flags:
   176    -C, --channelID string               The channel on which this command should be executed
   177        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
   178    -h, --help                           help for list
   179        --installed                      Get the installed chaincodes on a peer
   180        --instantiated                   Get the instantiated chaincodes on a channel
   181        --peerAddresses stringArray      The addresses of the peers to connect to
   182        --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
   183  
   184  Global Flags:
   185        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   186        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   187        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   188        --connTimeout duration                Timeout for client to connect (default 3s)
   189        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   190    -o, --orderer string                      Ordering service endpoint
   191        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   192        --tls                                 Use TLS when communicating with the orderer endpoint
   193        --transient string                    Transient map of arguments in JSON encoding
   194  ```
   195  
   196  
   197  ## peer chaincode package
   198  ```
   199  Package a chaincode and write the package to a file.
   200  
   201  Usage:
   202    peer chaincode package [outputfile] [flags]
   203  
   204  Flags:
   205    -s, --cc-package                  create CC deployment spec for owner endorsements instead of raw CC deployment spec
   206    -c, --ctor string                 Constructor message for the chaincode in JSON format (default "{}")
   207    -h, --help                        help for package
   208    -i, --instantiate-policy string   instantiation policy for the chaincode
   209    -l, --lang string                 Language the chaincode is written in (default "golang")
   210    -n, --name string                 Name of the chaincode
   211    -p, --path string                 Path to chaincode
   212    -S, --sign                        if creating CC deployment spec package for owner endorsements, also sign it with local MSP
   213    -v, --version string              Version of the chaincode specified in install/instantiate/upgrade commands
   214  
   215  Global Flags:
   216        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   217        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   218        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   219        --connTimeout duration                Timeout for client to connect (default 3s)
   220        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   221    -o, --orderer string                      Ordering service endpoint
   222        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   223        --tls                                 Use TLS when communicating with the orderer endpoint
   224        --transient string                    Transient map of arguments in JSON encoding
   225  ```
   226  
   227  
   228  ## peer chaincode query
   229  ```
   230  Get endorsed result of chaincode function call and print it. It won't generate transaction.
   231  
   232  Usage:
   233    peer chaincode query [flags]
   234  
   235  Flags:
   236    -C, --channelID string               The channel on which this command should be executed
   237        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
   238    -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
   239    -h, --help                           help for query
   240    -x, --hex                            If true, output the query value byte array in hexadecimal. Incompatible with --raw
   241    -n, --name string                    Name of the chaincode
   242        --peerAddresses stringArray      The addresses of the peers to connect to
   243    -r, --raw                            If true, output the query value as raw bytes, otherwise format as a printable string
   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  
   246  Global Flags:
   247        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   248        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   249        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   250        --connTimeout duration                Timeout for client to connect (default 3s)
   251        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   252    -o, --orderer string                      Ordering service endpoint
   253        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   254        --tls                                 Use TLS when communicating with the orderer endpoint
   255        --transient string                    Transient map of arguments in JSON encoding
   256  ```
   257  
   258  
   259  ## peer chaincode signpackage
   260  ```
   261  Sign the specified chaincode package
   262  
   263  Usage:
   264    peer chaincode signpackage [flags]
   265  
   266  Flags:
   267    -h, --help   help for signpackage
   268  
   269  Global Flags:
   270        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   271        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   272        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   273        --connTimeout duration                Timeout for client to connect (default 3s)
   274        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   275    -o, --orderer string                      Ordering service endpoint
   276        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   277        --tls                                 Use TLS when communicating with the orderer endpoint
   278        --transient string                    Transient map of arguments in JSON encoding
   279  ```
   280  
   281  
   282  ## peer chaincode upgrade
   283  ```
   284  Upgrade an existing chaincode with the specified one. The new chaincode will immediately replace the existing chaincode upon the transaction committed.
   285  
   286  Usage:
   287    peer chaincode upgrade [flags]
   288  
   289  Flags:
   290    -C, --channelID string               The channel on which this command should be executed
   291        --collections-config string      The fully qualified path to the collection JSON file including the file name
   292        --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
   293    -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
   294    -E, --escc string                    The name of the endorsement system chaincode to be used for this chaincode
   295    -h, --help                           help for upgrade
   296    -l, --lang string                    Language the chaincode is written in (default "golang")
   297    -n, --name string                    Name of the chaincode
   298    -p, --path string                    Path to chaincode
   299        --peerAddresses stringArray      The addresses of the peers to connect to
   300    -P, --policy string                  The endorsement policy associated to this chaincode
   301        --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
   302    -v, --version string                 Version of the chaincode specified in install/instantiate/upgrade commands
   303    -V, --vscc string                    The name of the verification system chaincode to be used for this chaincode
   304  
   305  Global Flags:
   306        --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
   307        --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
   308        --clientauth                          Use mutual TLS when communicating with the orderer endpoint
   309        --connTimeout duration                Timeout for client to connect (default 3s)
   310        --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
   311    -o, --orderer string                      Ordering service endpoint
   312        --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
   313        --tls                                 Use TLS when communicating with the orderer endpoint
   314        --transient string                    Transient map of arguments in JSON encoding
   315  ```
   316  
   317  ## Example Usage
   318  
   319  ### peer chaincode instantiate examples
   320  
   321  Here are some examples of the `peer chaincode instantiate` command, which
   322  instantiates the chaincode named `mycc` at version `1.0` on channel
   323  `mychannel`:
   324  
   325    * Using the `--tls` and `--cafile` global flags to instantiate the chaincode
   326      in a network with TLS enabled:
   327  
   328      ```
   329      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
   330      peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
   331  
   332      2018-02-22 16:33:53.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
   333      2018-02-22 16:33:53.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
   334      2018-02-22 16:34:08.698 UTC [main] main -> INFO 003 Exiting.....
   335  
   336      ```
   337  
   338    * Using only the command-specific options to instantiate the chaincode in a
   339      network with TLS disabled:
   340  
   341      ```
   342      peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
   343  
   344  
   345      2018-02-22 16:34:09.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
   346      2018-02-22 16:34:09.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
   347      2018-02-22 16:34:24.698 UTC [main] main -> INFO 003 Exiting.....
   348      ```
   349  
   350  ### peer chaincode invoke example
   351  
   352  Here is an example of the `peer chaincode invoke` command:
   353  
   354    * Invoke the chaincode named `mycc` at version `1.0` on channel `mychannel`
   355      on `peer0.org1.example.com:7051` and `peer0.org2.example.com:9051` (the
   356      peers defined by `--peerAddresses`), requesting to move 10 units from
   357      variable `a` to variable `b`:
   358  
   359      ```
   360      peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 -c '{"Args":["invoke","a","b","10"]}'
   361  
   362      2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
   363      2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
   364      .
   365      .
   366      .
   367      2018-02-22 16:34:27.106 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response:<status:200 message:"OK" > payload:"\n \237mM\376? [\214\002 \332\204\035\275q\227\2132A\n\204&\2106\037W|\346#\3413\274\022Y\nE\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022-\n\004mycc\022%\n\007\n\001a\022\002\010\003\n\007\n\001b\022\002\010\003\032\007\n\001a\032\00290\032\010\n\001b\032\003210\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement:<endorser:"\n\007Org1MSP\022\262\006-----BEGIN CERTIFICATE-----\nMIICLjCCAdWgAwIBAgIRAJYomxY2cqHA/fbRnH5a/bwwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMjIyMTYyODE0WhcNMjgwMjIwMTYyODE0\nWjBwMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzETMBEGA1UECxMKRmFicmljUGVlcjEfMB0GA1UEAxMWcGVl\ncjAub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDEa\nWNNniN3qOCQL89BGWfY39f5V3o1pi//7JFDHATJXtLgJhkK5KosDdHuKLYbCqvge\n46u3AC16MZyJRvKBiw6jTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAA\nMCsGA1UdIwQkMCKAIN7dJR9dimkFtkus0R5pAOlRz5SA3FB5t8Eaxl9A7lkgMAoG\nCCqGSM49BAMCA0cAMEQCIC2DAsO9QZzQmKi8OOKwcCh9Gd01YmWIN3oVmaCRr8C7\nAiAlQffq2JFlbh6OWURGOko6RckizG8oVOldZG/Xj3C8lA==\n-----END CERTIFICATE-----\n" signature:"0D\002 \022_\342\350\344\231G&\237\n\244\375\302J\220l\302\345\210\335D\250y\253P\0214:\221e\332@\002 \000\254\361\224\247\210\214L\277\370\222\213\217\301\r\341v\227\265\277\336\256^\217\336\005y*\321\023\025\367" >
   368      2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200
   369      2018-02-22 16:34:27.107 UTC [main] main -> INFO 00c Exiting.....
   370  
   371      ```
   372  
   373      Here you can see that the invoke was submitted successfully based on the log
   374      message:
   375  
   376      ```
   377      2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200
   378  
   379      ```
   380  
   381      A successful response indicates that the transaction was submitted for ordering
   382      successfully. The transaction will then be added to a block and, finally, validated
   383      or invalidated by each peer on the channel.
   384  
   385  ### peer chaincode list example
   386  
   387  Here are some examples of the `peer chaincode list ` command:
   388  
   389    * Using the `--installed` flag to list the chaincodes installed on a peer.
   390  
   391      ```
   392      peer chaincode list --installed
   393  
   394      Get installed chaincodes on peer:
   395      Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric-samples/chaincode/abstore/go, Id: 8cc2730fdafd0b28ef734eac12b29df5fc98ad98bdb1b7e0ef96265c3d893d61
   396      2018-02-22 17:07:13.476 UTC [main] main -> INFO 001 Exiting.....
   397      ```
   398  
   399      You can see that the peer has installed a chaincode called `mycc` which is at
   400      version `1.0`.
   401  
   402    * Using the `--instantiated` in combination with the `-C` (channel ID) flag to
   403      list the chaincodes instantiated on a channel.
   404  
   405      ```
   406      peer chaincode list --instantiated -C mychannel
   407  
   408      Get instantiated chaincodes on channel mychannel:
   409      Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric-samples/chaincode/abstore/go, Escc: escc, Vscc: vscc
   410      2018-02-22 17:07:42.969 UTC [main] main -> INFO 001 Exiting.....
   411  
   412      ```
   413  
   414      You can see that chaincode `mycc` at version `1.0` is instantiated on
   415      channel `mychannel`.
   416  
   417  ### peer chaincode package example
   418  
   419  Here is an example of the `peer chaincode package` command, which
   420  packages the chaincode named `mycc` at version `1.1`, creates the chaincode
   421  deployment spec, signs the package using the local MSP, and outputs it as
   422  `ccpack.out`:
   423  
   424    ```
   425      peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric-samples/chaincode/abstore/go -v 1.1 -s -S
   426      .
   427      .
   428      .
   429      2018-02-22 17:27:01.404 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
   430      2018-02-22 17:27:01.405 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
   431      .
   432      .
   433      .
   434      2018-02-22 17:27:01.879 UTC [chaincodeCmd] chaincodePackage -> DEBU 011 Packaged chaincode into deployment spec of size <3426>, with args = [ccpack.out]
   435      2018-02-22 17:27:01.879 UTC [main] main -> INFO 012 Exiting.....
   436  
   437      ```
   438  
   439  ### peer chaincode query example
   440  
   441  Here is an example of the `peer chaincode query` command, which queries the
   442  peer ledger for the chaincode named `mycc` at version `1.0` for the value of
   443  variable `a`:
   444  
   445    * You can see from the output that variable `a` had a value of 90 at the time of
   446      the query.
   447  
   448      ```
   449      peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
   450  
   451      2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
   452      2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
   453      Query Result: 90
   454  
   455      ```
   456  
   457  ### peer chaincode signpackage example
   458  
   459  Here is an example of the `peer chaincode signpackage` command, which accepts an
   460  existing signed  package and creates a new one with signature of the local MSP
   461  appended to it.
   462  
   463    ```
   464    peer chaincode signpackage ccwith1sig.pak ccwith2sig.pak
   465    Wrote signed package to ccwith2sig.pak successfully
   466    2018-02-24 19:32:47.189 EST [main] main -> INFO 002 Exiting.....
   467    ```
   468  
   469  ### peer chaincode upgrade example
   470  
   471  Here is an example of the `peer chaincode upgrade` command, which
   472  upgrades the chaincode named `mycc` at version `1.1` on channel
   473  `mychannel` to version `1.2`, which contains a new variable `c`:
   474  
   475    * Using the `--tls` and `--cafile` global flags to upgrade the chaincode
   476      in a network with TLS enabled:
   477  
   478      ```
   479      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
   480      peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.2 -c '{"Args":["init","a","100","b","200","c","300"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
   481      .
   482      .
   483      .
   484      2018-02-22 18:26:31.433 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
   485      2018-02-22 18:26:31.434 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
   486      2018-02-22 18:26:31.435 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode enabled
   487      2018-02-22 18:26:31.435 UTC [chaincodeCmd] upgrade -> DEBU 006 Get upgrade proposal for chaincode <name:"mycc" version:"1.1" >
   488      .
   489      .
   490      .
   491      2018-02-22 18:26:46.687 UTC [chaincodeCmd] upgrade -> DEBU 009 endorse upgrade proposal, get response <status:200 message:"OK" payload:"\n\004mycc\022\0031.1\032\004escc\"\004vscc*,\022\014\022\n\010\001\022\002\010\000\022\002\010\001\032\r\022\013\n\007Org1MSP\020\003\032\r\022\013\n\007Org2MSP\020\0032f\n \261g(^v\021\220\240\332\251\014\204V\210P\310o\231\271\036\301\022\032\205fC[|=\215\372\223\022 \311b\025?\323N\343\325\032\005\365\236\001XKj\004E\351\007\247\265fu\305j\367\331\275\253\307R\032 \014H#\014\272!#\345\306s\323\371\350\364\006.\000\356\230\353\270\263\215\217\303\256\220i^\277\305\214: \375\200zY\275\203}\375\244\205\035\340\226]l!uE\334\273\214\214\020\303\3474\360\014\234-\006\315B\031\022\010\022\006\010\001\022\002\010\000\032\r\022\013\n\007Org1MSP\020\001" >
   492      .
   493      .
   494      .
   495      2018-02-22 18:26:46.693 UTC [chaincodeCmd] upgrade -> DEBU 00c Get Signed envelope
   496      2018-02-22 18:26:46.693 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00d Send signed envelope to orderer
   497      2018-02-22 18:26:46.908 UTC [main] main -> INFO 00e Exiting.....
   498      ```
   499  
   500    * Using only the command-specific options to upgrade the chaincode in a
   501      network with TLS disabled:
   502  
   503      ```
   504      peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n mycc -v 1.2 -c '{"Args":["init","a","100","b","200","c","300"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
   505      .
   506      .
   507      .
   508      2018-02-22 18:28:31.433 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
   509      2018-02-22 18:28:31.434 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
   510      2018-02-22 18:28:31.435 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode enabled
   511      2018-02-22 18:28:31.435 UTC [chaincodeCmd] upgrade -> DEBU 006 Get upgrade proposal for chaincode <name:"mycc" version:"1.1" >
   512      .
   513      .
   514      .
   515      2018-02-22 18:28:46.687 UTC [chaincodeCmd] upgrade -> DEBU 009 endorse upgrade proposal, get response <status:200 message:"OK" payload:"\n\004mycc\022\0031.1\032\004escc\"\004vscc*,\022\014\022\n\010\001\022\002\010\000\022\002\010\001\032\r\022\013\n\007Org1MSP\020\003\032\r\022\013\n\007Org2MSP\020\0032f\n \261g(^v\021\220\240\332\251\014\204V\210P\310o\231\271\036\301\022\032\205fC[|=\215\372\223\022 \311b\025?\323N\343\325\032\005\365\236\001XKj\004E\351\007\247\265fu\305j\367\331\275\253\307R\032 \014H#\014\272!#\345\306s\323\371\350\364\006.\000\356\230\353\270\263\215\217\303\256\220i^\277\305\214: \375\200zY\275\203}\375\244\205\035\340\226]l!uE\334\273\214\214\020\303\3474\360\014\234-\006\315B\031\022\010\022\006\010\001\022\002\010\000\032\r\022\013\n\007Org1MSP\020\001" >
   516      .
   517      .
   518      .
   519      2018-02-22 18:28:46.693 UTC [chaincodeCmd] upgrade -> DEBU 00c Get Signed envelope
   520      2018-02-22 18:28:46.693 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00d Send signed envelope to orderer
   521      2018-02-22 18:28:46.908 UTC [main] main -> INFO 00e Exiting.....
   522      ```
   523  
   524  <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>.