peer chaincode

The peer chaincode command allows administrators to perform chaincode related operations on a peer, such as installing, instantiating, invoking, packaging, querying, and upgrading chaincode.

Syntax

The peer chaincode command has the following subcommands:

  • install

  • instantiate

  • invoke

  • list

  • package

  • query

  • signpackage

  • upgrade

The different subcommand options (install, instantiate…) relate to the different chaincode operations that are relevant to a peer. For example, use the peer chaincode install subcommand option to install a chaincode on a peer, or the peer chaincode query subcommand option to query a chaincode for the current value on a peer’s ledger.

Some subcommands take flag --ctor, of which the value must be a JSON string that has either key ‘Args’ or ‘Function’ and ‘Args’. These keys are case-insensitive.

If the JSON string only has the Args key, the key value is an array, where the first array element is the target function to call, and the subsequent elements are arguments of the function. If the JSON string has both ‘Function’ and ‘Args’, the value of Function is the target function to call, and the value of Args is an array of arguments of the function. For instance, {"Args":["GetAllAssets"]} is equivalent to {"Function":"GetAllAssets", "Args":[]}.

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

Flags

Each peer chaincode subcommand has both a set of flags specific to an individual subcommand, as well as a set of global flags that relate to all peer chaincode subcommands. Not all subcommands would use these flags. For instance, the query subcommand does not need the --orderer flag.

The individual flags are described with the relevant subcommand. The global flags are

  • --cafile <string>

    Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint

  • --certfile <string>

    Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint

  • --keyfile <string>

    Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint

  • -o or --orderer <string>

    Ordering service endpoint specified as <hostname or IP address>:<port>

  • --ordererTLSHostnameOverride <string>

    The hostname override to use when validating the TLS connection to the orderer

  • --tls

    Use TLS when communicating with the orderer endpoint

  • --transient <string>

    Transient map of arguments in JSON encoding

Flags of type stringArray are to be repeated rather than concatenating their values. For example, you will use --peerAddresses localhost:9051 --peerAddresses localhost:7051 rather than --peerAddresses "localhost:9051 localhost:7051".

peer chaincode install

  1. Install a chaincode on a peer. This installs a chaincode deployment spec package (if provided) or packages the specified chaincode before subsequently installing it.
  2. Usage:
  3. peer chaincode install [flags]
  4. Flags:
  5. --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  6. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  7. -h, --help help for install
  8. -l, --lang string Language the chaincode is written in (default "golang")
  9. -n, --name string Name of the chaincode
  10. -p, --path string Path to chaincode
  11. --peerAddresses stringArray The addresses of the peers to connect to
  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. -v, --version string Version of the chaincode specified in install/instantiate/upgrade commands
  14. Global Flags:
  15. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  16. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  17. --clientauth Use mutual TLS when communicating with the orderer endpoint
  18. --connTimeout duration Timeout for client to connect (default 3s)
  19. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  20. -o, --orderer string Ordering service endpoint
  21. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  22. --tls Use TLS when communicating with the orderer endpoint
  23. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  24. --transient string Transient map of arguments in JSON encoding

peer chaincode instantiate

  1. Deploy the specified chaincode to the network.
  2. Usage:
  3. peer chaincode instantiate [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --collections-config string The fully qualified path to the collection JSON file including the file name
  7. --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  8. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  9. -E, --escc string The name of the endorsement system chaincode to be used for this chaincode
  10. -h, --help help for instantiate
  11. -l, --lang string Language the chaincode is written in (default "golang")
  12. -n, --name string Name of the chaincode
  13. --peerAddresses stringArray The addresses of the peers to connect to
  14. -P, --policy string The endorsement policy associated to this chaincode
  15. --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
  16. -v, --version string Version of the chaincode specified in install/instantiate/upgrade commands
  17. -V, --vscc string The name of the verification system chaincode to be used for this chaincode
  18. Global Flags:
  19. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  20. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  21. --clientauth Use mutual TLS when communicating with the orderer endpoint
  22. --connTimeout duration Timeout for client to connect (default 3s)
  23. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  24. -o, --orderer string Ordering service endpoint
  25. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  26. --tls Use TLS when communicating with the orderer endpoint
  27. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  28. --transient string Transient map of arguments in JSON encoding

peer chaincode invoke

  1. Invoke the specified chaincode. It will try to commit the endorsed transaction to the network.
  2. Usage:
  3. peer chaincode invoke [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  7. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  8. -h, --help help for invoke
  9. -I, --isInit Is this invocation for init (useful for supporting legacy chaincodes in the new lifecycle)
  10. -n, --name string Name of the chaincode
  11. --peerAddresses stringArray The addresses of the peers to connect to
  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. --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully
  14. --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)
  15. Global 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. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  21. -o, --orderer string Ordering service endpoint
  22. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  23. --tls Use TLS when communicating with the orderer endpoint
  24. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  25. --transient string Transient map of arguments in JSON encoding

peer chaincode list

  1. Get the instantiated chaincodes in the channel if specify channel, or get installed chaincodes on the peer
  2. Usage:
  3. peer chaincode list [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --connectionProfile string 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 list
  8. --installed Get the installed chaincodes on a peer
  9. --instantiated Get the instantiated chaincodes on a channel
  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
  22. --transient string Transient map of arguments in JSON encoding

peer chaincode package

  1. Package a chaincode and write the package to a file.
  2. Usage:
  3. peer chaincode package [outputfile] [flags]
  4. Flags:
  5. -s, --cc-package create CC deployment spec for owner endorsements instead of raw CC deployment spec
  6. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  7. -h, --help help for package
  8. -i, --instantiate-policy string instantiation policy for the chaincode
  9. -l, --lang string Language the chaincode is written in (default "golang")
  10. -n, --name string Name of the chaincode
  11. -p, --path string Path to chaincode
  12. -S, --sign if creating CC deployment spec package for owner endorsements, also sign it with local MSP
  13. -v, --version string Version of the chaincode specified in install/instantiate/upgrade commands
  14. Global Flags:
  15. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  16. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  17. --clientauth Use mutual TLS when communicating with the orderer endpoint
  18. --connTimeout duration Timeout for client to connect (default 3s)
  19. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  20. -o, --orderer string Ordering service endpoint
  21. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  22. --tls Use TLS when communicating with the orderer endpoint
  23. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  24. --transient string Transient map of arguments in JSON encoding

peer chaincode query

  1. Get endorsed result of chaincode function call and print it. It won't generate transaction.
  2. Usage:
  3. peer chaincode query [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  7. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  8. -h, --help help for query
  9. -x, --hex If true, output the query value byte array in hexadecimal. Incompatible with --raw
  10. -n, --name string Name of the chaincode
  11. --peerAddresses stringArray The addresses of the peers to connect to
  12. -r, --raw If true, output the query value as raw bytes, otherwise format as a printable string
  13. --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
  14. Global Flags:
  15. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  16. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  17. --clientauth Use mutual TLS when communicating with the orderer endpoint
  18. --connTimeout duration Timeout for client to connect (default 3s)
  19. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  20. -o, --orderer string Ordering service endpoint
  21. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  22. --tls Use TLS when communicating with the orderer endpoint
  23. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  24. --transient string Transient map of arguments in JSON encoding

peer chaincode signpackage

  1. Sign the specified chaincode package
  2. Usage:
  3. peer chaincode signpackage [flags]
  4. Flags:
  5. -h, --help help for signpackage
  6. Global Flags:
  7. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  8. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  9. --clientauth Use mutual TLS when communicating with the orderer endpoint
  10. --connTimeout duration Timeout for client to connect (default 3s)
  11. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  12. -o, --orderer string Ordering service endpoint
  13. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  14. --tls Use TLS when communicating with the orderer endpoint
  15. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  16. --transient string Transient map of arguments in JSON encoding

peer chaincode upgrade

  1. Upgrade an existing chaincode with the specified one. The new chaincode will immediately replace the existing chaincode upon the transaction committed.
  2. Usage:
  3. peer chaincode upgrade [flags]
  4. Flags:
  5. -C, --channelID string The channel on which this command should be executed
  6. --collections-config string The fully qualified path to the collection JSON file including the file name
  7. --connectionProfile string Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  8. -c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
  9. -E, --escc string The name of the endorsement system chaincode to be used for this chaincode
  10. -h, --help help for upgrade
  11. -l, --lang string Language the chaincode is written in (default "golang")
  12. -n, --name string Name of the chaincode
  13. -p, --path string Path to chaincode
  14. --peerAddresses stringArray The addresses of the peers to connect to
  15. -P, --policy string The endorsement policy associated to this chaincode
  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, --version string Version of the chaincode specified in install/instantiate/upgrade commands
  18. -V, --vscc string The name of the verification system chaincode to be used for this chaincode
  19. Global Flags:
  20. --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
  21. --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
  22. --clientauth Use mutual TLS when communicating with the orderer endpoint
  23. --connTimeout duration Timeout for client to connect (default 3s)
  24. --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  25. -o, --orderer string Ordering service endpoint
  26. --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer
  27. --tls Use TLS when communicating with the orderer endpoint
  28. --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
  29. --transient string Transient map of arguments in JSON encoding

Example Usage

peer chaincode instantiate examples

Here are some examples of the peer chaincode instantiate command, which instantiates the chaincode named mycc at version 1.0 on channel mychannel:

  • Using the --tls and --cafile global flags to instantiate the chaincode in a network with TLS enabled:

    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 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')"
    3. 2018-02-22 16:33:53.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    4. 2018-02-22 16:33:53.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    5. 2018-02-22 16:34:08.698 UTC [main] main -> INFO 003 Exiting.....
  • Using only the command-specific options to instantiate the chaincode in a network with TLS disabled:

    ``` 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’)”

  1. 2018-02-22 16:34:09.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
  2. 2018-02-22 16:34:09.324 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
  3. 2018-02-22 16:34:24.698 UTC [main] main -> INFO 003 Exiting.....
  4. ```

peer chaincode invoke example

Here is an example of the peer chaincode invoke command:

  • Invoke the chaincode named mycc at version 1.0 on channel mychannel on peer0.org1.example.com:7051 and peer0.org2.example.com:9051 (the peers defined by --peerAddresses), requesting to move 10 units from variable a to variable b:

    1. 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"]}'
    2. 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    3. 2018-02-22 16:34:27.069 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    4. .
    5. .
    6. .
    7. 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" >
    8. 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200
    9. 2018-02-22 16:34:27.107 UTC [main] main -> INFO 00c Exiting.....

    Here you can see that the invoke was submitted successfully based on the log message:

    1. 2018-02-22 16:34:27.107 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200

    A successful response indicates that the transaction was submitted for ordering successfully. The transaction will then be added to a block and, finally, validated or invalidated by each peer on the channel.

Here is an example of how to format the peer chaincode invoke command when the chaincode package includes multiple smart contracts.

  • If you are using the contract-api, the name you pass to super("MyContract") can be used as a prefix.

    1. peer chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyContract:methodName", "{}"] }'
    2. peer chaincode invoke -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{ "Args": ["MyOtherContract:methodName", "{}"] }'

peer chaincode list example

Here are some examples of the peer chaincode list command:

  • Using the --installed flag to list the chaincodes installed on a peer.

    1. peer chaincode list --installed
    2. Get installed chaincodes on peer:
    3. Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric-samples/chaincode/abstore/go, Id: 8cc2730fdafd0b28ef734eac12b29df5fc98ad98bdb1b7e0ef96265c3d893d61
    4. 2018-02-22 17:07:13.476 UTC [main] main -> INFO 001 Exiting.....

    You can see that the peer has installed a chaincode called mycc which is at version 1.0.

  • Using the --instantiated in combination with the -C (channel ID) flag to list the chaincodes instantiated on a channel.

    1. peer chaincode list --instantiated -C mychannel
    2. Get instantiated chaincodes on channel mychannel:
    3. Name: mycc, Version: 1.0, Path: github.com/hyperledger/fabric-samples/chaincode/abstore/go, Escc: escc, Vscc: vscc
    4. 2018-02-22 17:07:42.969 UTC [main] main -> INFO 001 Exiting.....

    You can see that chaincode mycc at version 1.0 is instantiated on channel mychannel.

peer chaincode package example

Here is an example of the peer chaincode package command, which packages the chaincode named mycc at version 1.1, creates the chaincode deployment spec, signs the package using the local MSP, and outputs it as ccpack.out:

  1. peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric-samples/chaincode/abstore/go -v 1.1 -s -S
  2. .
  3. .
  4. .
  5. 2018-02-22 17:27:01.404 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
  6. 2018-02-22 17:27:01.405 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
  7. .
  8. .
  9. .
  10. 2018-02-22 17:27:01.879 UTC [chaincodeCmd] chaincodePackage -> DEBU 011 Packaged chaincode into deployment spec of size <3426>, with args = [ccpack.out]
  11. 2018-02-22 17:27:01.879 UTC [main] main -> INFO 012 Exiting.....

peer chaincode query example

Here is an example of the peer chaincode query command, which queries the peer ledger for the chaincode named mycc at version 1.0 for the value of variable a:

  • You can see from the output that variable a had a value of 90 at the time of the query.

    1. peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    2. 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    3. 2018-02-22 16:34:30.816 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    4. Query Result: 90

peer chaincode signpackage example

Here is an example of the peer chaincode signpackage command, which accepts an existing signed package and creates a new one with signature of the local MSP appended to it.

  1. peer chaincode signpackage ccwith1sig.pak ccwith2sig.pak Wrote signed package to ccwith2sig.pak successfully 2018-02-24 19:32:47.189 EST \[main\] main -&gt; INFO 002 Exiting…..

peer chaincode upgrade example

Here is an example of the peer chaincode upgrade command, which upgrades the chaincode named mycc at version 1.1 on channel mychannel to version 1.2, which contains a new variable c:

  • Using the --tls and --cafile global flags to upgrade the chaincode in a network with TLS enabled:

    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 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')"
    3. .
    4. .
    5. .
    6. 2018-02-22 18:26:31.433 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    7. 2018-02-22 18:26:31.434 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    8. 2018-02-22 18:26:31.435 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode enabled
    9. 2018-02-22 18:26:31.435 UTC [chaincodeCmd] upgrade -> DEBU 006 Get upgrade proposal for chaincode <name:"mycc" version:"1.1" >
    10. .
    11. .
    12. .
    13. 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" >
    14. .
    15. .
    16. .
    17. 2018-02-22 18:26:46.693 UTC [chaincodeCmd] upgrade -> DEBU 00c Get Signed envelope
    18. 2018-02-22 18:26:46.693 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00d Send signed envelope to orderer
    19. 2018-02-22 18:26:46.908 UTC [main] main -> INFO 00e Exiting.....
  • Using only the command-specific options to upgrade the chaincode in a network with TLS disabled:

    1. 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')"
    2. .
    3. .
    4. .
    5. 2018-02-22 18:28:31.433 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
    6. 2018-02-22 18:28:31.434 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
    7. 2018-02-22 18:28:31.435 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode enabled
    8. 2018-02-22 18:28:31.435 UTC [chaincodeCmd] upgrade -> DEBU 006 Get upgrade proposal for chaincode <name:"mycc" version:"1.1" >
    9. .
    10. .
    11. .
    12. 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" >
    13. .
    14. .
    15. .
    16. 2018-02-22 18:28:46.693 UTC [chaincodeCmd] upgrade -> DEBU 00c Get Signed envelope
    17. 2018-02-22 18:28:46.693 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00d Send signed envelope to orderer
    18. 2018-02-22 18:28:46.908 UTC [main] main -> INFO 00e Exiting.....

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