Deploy Your Chaincode Using Visual Studio Code

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 the Chaincode to a Local Hyperledger Fabric Network

Once you have created your chaincode project, you can test it in a local Hyperledger Fabric basic network.

When you install the Blockchain App Builder extension for VS Code, it automatically creates a Hyperledger Fabric network with a single channel. This will be listed as Local Environment in the Environments pane. You can't delete or modify this environment; you can just deploy chaincodes to it and rebuild it if it stops working correctly.

Blockchain App Builder chaincode deployment starts the Hyperledger Fabric basic network, other services, and installs and deploys the chaincode for you.

  1. In the Chaincode Details pane, select Deploy.
  2. In the deployment wizard:
    • Ensure the correct chaincode name is selected.
    • Select your target environment - for local deployment choose Local Environment.
    • Select the channel you want to deploy to. A channel named "mychannel" is created by default with the extension's installation, and can be used for testing.
    • Optionally enter any initial parameters that may be required.
    • For token projects, the first time that you deploy you must enter a list of token admins as a parameter. The list is an array of {user_id, org_id} information that specifies the token admins. For the local Hyperledger Fabric network, use the value Org1MSP for the org_id field. For NFT chaincodes, the keys for the adminList parameter are userId and orgId for TypeScript and UserId and OrgId for Go. After the first time you deploy, you can supply an empty array for the adminList parameter or you can use the adminList parameter to add token admins. Other deployers who are not the first-time deployer must supply an empty array for the adminList parameter. To do so, open the Init parameter list in the deployment pane and then click the minus sign (–) button next to the adminList parameter, which will select an empty array.
  3. Click Deploy.

When the chaincode has finished deploying, the Output console will state that it has successfully installed and deployed it on the given channel.

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 in the Output console:
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
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 deploying again:
sudo chmod -R 777 /usr/local/go
Deployment failure
Due to deployment failure, corrupt deployment, a Docker peer container being full, or a Docker peer being killed in the 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: Rebuild your runtime by selecting your local environment in the Environments pane, right-clicking and selecting Rebuild Local Environment. Attempt to deploy again.
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. In the App Builder Environments pane, right-click your local environment and select Rebuild Local Environment.

Deploy Your Chaincode to a Remote Oracle Blockchain Platform Network

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

Create a Connection Configuration to an Oracle Blockchain Platform Instance

You must have a Blockchain Platform instance up and running to complete this step.

  1. In the Visual Studio Code Environments pane, click the Create Environment icon.
  2. On the Environments Details wizard:
    • Enter the name for your remote environment.
    • Enter a description.
    • In Remote Url, enter the URL of the remote Oracle Blockchain Platform instance.
    • Enter the Oracle Identity Cloud Service user name and password for an Oracle Blockchain Platform user with the ADMIN or REST_CLIENT roles. To invoke the chaincode, only the REST_CLIENT role is necessary. To deploy or upgrade the chaincode, the IDCS user must also be assigned the ADMIN role. For more information about users and roles, see Set Up Users and Application Roles.
  3. Click Create to save the environment. The user name and password are saved temporarily in the local Visual Studio Code session. If you close Visual Studio Code and then start a new Visual Studio Code session, you must enter the user name and password again.

Deploy Your Chaincode

  1. Select the chaincode project you want to deploy in the Chaincodes pane.
  2. In the Chaincode Details pane, select Deploy.
  3. In the deployment wizard, the name of the chaincode project should be pre-filled.
    • Select your target environment - for remote deployment choose the Oracle Blockchain Platform environment you set up previously.
    • Enter the name of the channel you want to deploy to.
    • Optionally set any required initial parameters.
  4. Click Deploy.
After the chaincode is successfully deployed to the remote Oracle Blockchain Platform, the console log will show that the following events occurred:
  • The Oracle Blockchain Platform details were successfully fetched.
  • The list of peers was successfully fetched.
  • The chaincode project was successfully installed.
  • The chaincode project was successfully approved and committed.
  • The chaincode was successfully deployed on each peer and the channel.

In an environment with multiple organizations, to re-deploy the chaincode on the same channel through a participant instance, use the console to deploy the chaincode.

Upgrading the Chaincode Project

Upgrading the chaincode is handled automatically by Blockchain App Builder. After you make changes to your chaincode, just deploy again, which will automatically upgrade the project for you. When you run the upgrade process, you can pass an empty array for the adminList parameter or use the adminList parameter to add token admins. If you are not the first-time deployer, you must supply an empty array for the adminList parameter. To pass an empty array for the adminList parameter, open the Init parameter list in the deployment pane and then click the minus sign (–) button next to the adminList parameter, which will select an empty array.

If your upgrade is successful, the log will show that the following events occurred:
  • The Oracle Blockchain Platform details were successfully fetched.
  • The list of peers was successfully fetched.
  • A check was made to determine if the chaincode project is already installed, and if so, the version was fetched.
  • The chaincode version was successfully upgraded (for example, from version 1.0 to 2.0).

In an environment with multiple organizations, to upgrade the chaincode, use the console and manually approve the chaincode from the participants.

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.

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

  1. Select your chaincode project in the Chaincodes pane.
  2. Right-click and select Package.
  3. Select a location to save the package to, and then click Select Output Folder.

Because of changes to software prerequisites, when you run the Package function for TypeScript chaincode, you are prompted for the provisioning date of the Oracle Blockchain Platform instance that you want to create the package for. The TypeScript chaincode created in Blockchain App Builder is not compatible with previous versions of Oracle Blockchain Platform without changes to the underlying infrastructure. Blockchain App Builder packages the chaincode infrastructure accordingly based on your selection.

When the command completes successfully, the location of the package is returned.