Deploy Your Chaincode Using the CLI

Once your chaincode project is created, you can deploy it locally to the automatically generated Hyperledger Fabric network, or remotely to your Oracle Blockchain Platform Cloud or Enterprise Edition. You can also package the chaincode project for manual deployment to Oracle Blockchain Platform.

Deploy Your Chaincode to a Local Hyperledger Fabric Network

Once you have created your chaincode project, you can deploy it to a local Hyperledger Fabric network. This basic single-channel network is created for you when you install Blockchain App Builder.

The Blockchain App Builder ochain run command starts the Hyperledger Fabric network, other services, and installs and instantiates the chaincode for you.

my-mac:GOProject myname$ ochain run -h
Usage: run [options] [...args]
Run chaincode project locally in debug mode.

Arguments :
[...args] (optional) Chaincode instantiate arguments. Arguments should be space separated.

Options:
-h, --help        output command usage information 
-D, --debug       enable debug logging
-P, --debug-port  (optional) specify debug process port
-b, --build       (optional) rebuild runtime if already exists
-p, --project     (optional) Path to Chaincode project to run. If not specified, it defaults to current directory.  

Examples :
$> ochain run   

If you would like to see the debug logs, you can pass the --debug option to the command. You can run the basic network and deploy the chaincode on a different port from the default by passing the --port option to the command.

Verifying

The following logs show that the chaincode has been installed and instantiated successfully.

my-mac:TSProject myname$ ochain run
Recreating orderer.example.com ... done
Recreating ca.example.com ... done
Recreating peer0.org1.example.com ... done
[2020-09-23T18: 04:09.132] [INFO] default -
============ Started Install Chaincode ============
[2020-09-23T18:04:09.193] [INFO] default Chaincode TSProject:l not installed.
[2020-09-23T18:04:09.317] [INFO] default - Successfully sent install Proposal and received ProposalResponse
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.317] [INFO] default -
============ Finished Install Chaincode ============
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.318] [INFO] default -
============ started instantiate Chaincode ============
[2020-09-23T18:04:09.366] [INFO] default - Successfully sent Proposal and received ProposalResponse
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction has been committed on peer localhost:7051
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction was valid.
[2020-09-23T18:04:11.435] [INFO] default - Successfully sent transaction to the orderer.
[2020-09-23T18:04:11.435] [INFO] default - Successfully instantiated chaincode TSProject on channel mychannel
[2020-09-23T18:04:11.435] [INFO] default - 
============ Finished instantiate Chaincode ============
[2020-09-23T18:04:11.4351 INFO] default - Successfully instantiated chaincode TSProject on channel mychannel 
INFO (Runtime): Chaincode TSProject installed and ready:
INFO (RunCommand): Chaincode TSProject deployed

Troubleshooting

You may encounter the following issues when running your chaincode project on a local network.

Missing Go permissions
While installing Go chaincode project in local network, you might see an error similar to the following:
My-Mac:GoProj myname$ ochain run
Starting ca.example.com    ... done
Starting orderer.example.com ... done
Starting peer0.orgl.example.com ... done
INFO (Runtime): 2020/06/22 22:57:09 build started

INFO (Runtime): Building ....

INFO (Runtime): go build runtime/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtine/ 
cgo.a: permission denied

ERROR (Runtime): go build runtine/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtime/
cgo.a: permission denied

INFO (Runtime): An error occurred while building: exit status 1

Stopping peer0.orgl.exmple.com ... done 
Stopping ca.example.com	... done
Stopping orderer.example.con ... done
This is due to missing permissions for Go. This error has been seen only in Mac OS. This is a known issue:
Solution: change the permissions of your $GOROOT and try ochain run again:
sudo chmod -R 777 /usr/local/go
Instantiation failure
Due to instantiation failure, corrupt instantiation, Docker peer container full, or Docker peer was killed in local network, you may see an error similar to:
============ Started instantiate Chaincode ============
[2028-19-01T19:25:lO.372] [ERROR] default - Error instantiating Chaincode GollGl on channel mychannel, detailed 
error: Error: error starting container: error starting container: Failed to generate platform-specific docker 
build: Failed to pull hyperledger/fabric-ccenv:latest : API error (404): manifest for hyperledger/ 
fabric-ccenv:latest not found: manifest unknown: manifest unknown [2020-19-01T19:25:10.372] (INFO) default -
============ Finished instantiate Chaincode ============
[2020-19-01119:25:10.372] [ERROR] default - Error: Error instantiating Chaincode Goll01 on channel mychannel, 
detailed error: Error: error starting container: error starting container: Failed to generate platfom-specific 
docker build: Failed to pull hyperledger/fabric-ccenv: latest : API error (404): manifest for hyperledger/ 
fabric-ccenv:lalest not found: manifest unknown: manifest unknown exited: signal: terminated 
INFO: exited: signal: terminated

ERROR: Error in Chaincode deployment
This is due to a peer container not able to start up properly again.
Solution: try the ochain run command again, but with the -b option. This option rebuilds the runtime for you.
ochain run -b
Environment Rebuild Required
You may see an error similar to:
Starting ca.example.com ... 
Starting orderer.example.com ... 
Starting orderer.example.com ... error
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: 
error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Starting ca.example.com... error
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Encountered errors while bringing up the project.
ERROR: Starting ca.example.com ... 
Starting orderer.example.com ... 
Starting orderer.example.com ... error
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Starting ca.example.com ... error
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for orderer.example.com  
Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
ERROR: for ca.example.com  
Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted
Encountered errors while bringing up the project.
ERROR: Error in Chaincode deployment
You need to rebuild your local environment:
ochain run -b

Deploy Your Chaincode to a Remote Oracle Blockchain Platform Network

Once you've instantiated and tested your chaincode project on a local network to ensure it's working as designed, you can deploy it to Oracle Blockchain Platform.

Creating Your Connection Profile

You can download your connection profile from the Oracle Blockchain Platform Cloud or Enterprise instance by navigating to the following location in your instance's console: on the Developer Tools tab, Application Development, and then Download the development package. Unzip the downloaded package. The contents should look similar to:
artifacts
    crypto
        ordererOrganizations
        peerOrganizations
network.yaml

Retrieve your admin credentials from your instance's console: on the Network tab, find your organization in the list. Click the More Actions icon for your organization, then select Export Admin Credential from your organization.

  1. Copy the admin certificate from the admin credentials to artifacts/crypto/ordererOrganizations/<instance-name>/signcert/<instance-name>-signcert.pem and artifacts/crypto/peerOrganizations/<instance-name>/signcert/<instance-name>-signcert.pem.
  2. Copy the admin key from the admin credentials to artifacts/crypto/ordererOrganizations/<instance-name>/keystore/<instance-name>-key.pem and artifacts/crypto/peerOrganizations/<instance-name>/keystore/<instance-name>-key.pem.

Note:

Keep in mind that if you're placing your connection profile in your project folder, if you're synching this with a content repository such as Github you might accidentally share your private keys. Ensure that everything private is added to your .gitignore file.

Log In Using the ochain login Command

You need to log in to the Oracle Blockchain Platform instance before deploying. The ochain login command will help you to authenticate and log in. It will prompt you asking for your username and password. The username and password are the same as the blockchain instance details.

Note:

The ochain login must be run before deploying the chaincode to a remote Oracle Blockchain Platform Cloud instance.

Usage: ochain login [options]

The following arguments can be used with this command:
my-mac:TSProject myname$ ochain login -h 
Usage: login [options]
Login to Oracle Blockchain Cloud Service instance 

Options :
    -h, --help            output command usage information
    -0, --debug           enable debug logging
    -P, --project         (optional) Path to Chaincode project to deploy. If not specified, it defaults to current directory.
    -d, --obp-dev-package (optional) Path to the downloaded and unzipped Oracle Blockchain Development Package. If not specified, it defaults to CURRENT_DIRECTORY/obp
    -u, --username        (optional) A user name that has install chaincode privileges. Contact your administrator for more details.
    -p, --password        (optional) user password. 

Examples:
$> ochain login
$> ochain login -u john.doe
S> ochain login -u john.doe -p MyPassword!

The login command uses the path to your downloaded Oracle Blockchain Development connection profile in the -d option. If not specified, it defaults to <current_project_directory>/obp

If your login is successful, a message will be returned stating "Login Successful".

Deploy

Usage: ochain deploy [options] [...args]

Following are the arguments and options taken by the ochain deploy command:

my-mac:TSProject myname$ ochain deploy -h 
Usage: deploy [options] [...args]
Deploy chaincode project to Oracle Blockchain Cloud Service

Arguments:
     [...args]    (optional) Chaincode instantiate arguments. Arguments should be comma separated.
 
Options :
    -h, --help               output command usage information
    -0, --debug              enable debug logging
    -P, --project            (optional) Path to Chaincode project to deploy. If not specified, it defaults to current directory.
    -d, --obp-dev-package    (optional) Path to the downloaded and unzipped Oracle Blockchain Development Package. If not specified, it defaults to CURRENT_DIRECTORY/obp
    -c, --channel            (optional) Blockchain Platform channel to deploy chaincode to. If not specified, defaults to the 'default' channel.
    -u, --wait               (optional) GRPC wait for ready timeout in milliseconds.
    -p, --username           (optional) A user name that has install chaincode privileges. Contact your administrator for more details.
    -v, --userversion        (optional) A user-specified chaincode version.
                             If a version isn't specified, for a new chaincode it will start at v1 and then increment to v2, v3, and so on.
                             For an existing chaincode, v1.a will increment to v1.a1, v1 will increment to v2, and v1.0 will increment to v1.1.

Examples:
$> ochain deploy -u john.doe -d <path to connection profile> -c channelname
Once the chaincode has successfully deployed to the remote Oracle Blockchain Platform, the log will show that:
  • It has successfully installed the chaincode project.
  • It has successfully instantiated the chaincode on each peer and the channel.

Updating the Chaincode Project

The upgrade of the chaincode is handled automatically by Blockchain App Builder. After you have made changes to your chaincode, just call the ochain deploy command again - this will automatically perform the update for you.

If your update is successful, the log will show
  • It has successfully upgraded the chaincode version (for example from version 1.0 to 2.0).
  • It has successfully installed the chaincode project.
  • It has successfully instantiated the chaincode on each peer and the channel.

Troubleshoot the Deployment

You may encounter the following issues when deploying your chaincode project on Oracle Blockchain Platform:

GRPC timeout error
While deploying to remote Oracle Blockchain Platform network, you may get the following GRPC timeout error:
[2020-09-23T18:40:17.923] [ERROR] default - Error Invoking chaincode "TSProject:" Failed to connect
before the deadline
This could be a network issue or GRPC wait timeout expired.
Deploy the chaincode again with -w <timeout> option. By default the timeout is set to 10000 ms.
> ochain deploy -u idcqa -d /Blockchain/DevTools/bp1/oraclebp1-instance-info -w 30000

Package Your Chaincode Project for Manual Deployment to Oracle Blockchain Platform

You can package your chaincode projects for manual deployment to Oracle Blockchain Platform Cloud or Enterprise Edition.

Usage: ochain package

The Package function creates a zip file containing only the build and distribution files - the binary, libs, node_modules, and test folders from your chaincode project are not included. This zip can be manually uploaded to Oracle Blockchain Platform for deployment.

my-mac:~ myname$ ochain package -h 
Usage: package [options]
Package and archive an Ochain chaincode project 
Options :
    -h, --help             output command usage information
    -D, --debug            enable debug logging
    -p, --project <path>   Path to the Ochain chaincode project to be packaged. If not specified, it defaults to current directory.
    -o, --out <path>       Path to the generated chaincode archive file. If not specified, it defaults to current directory.
About:
This CLI command packages and archives an existing chaincode project 
Examples:
$> ochain package --project <Path to the Ochain chaicode project> —out <Path to the generated chaincode archive file>

When the command completes successfully, the location of the package will be returned.

This command takes two optional arguments:
  • --project

    This option defines the location of the Blockchain App Builder chaincode project to be packaged. If not specified, it defaults to the current directory.

  • --out

    This option can be used to give the output path of the generated archive file. If not specified, it defaults to the current directory.

Example:
> ochain package -p /Blockchain/DevTools/bp1/CC -o /Blockchain/DevTools/bp1/output

"Your chaincode project has been packaged at /Blockchain/DevTools/bp1/output/CC.zip"