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 instantiates the chaincode for you.
- In the Chaincode Details pane, select Deploy.
- 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.
- Click Deploy.
When the chaincode has finished instantiating, the Output console will state that it has successfully instantiated it on the given channel, installed, and deployed the chaincode.
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 - Instantiation failure
- Due to instantiation failure, corrupt instantiation, 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 - 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
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.
Download Files Needed for Your Connection Profile
- Create a folder in your local storage to put the connection profile, and admin keys and certificates.
- Download your connection profile. In your Oracle Blockchain Platform instance's console, on the Developer Tools tab, Application Development, and then Download the development package.
- Retrieve your admin credentials from your instance's console. Click Network then Export Admin Credential from your organization.
- Copy the admin certificate from the admin credentials to
artifacts/crypto/ordererOrganizations/<instance-name>/signcert/<instance-name>-signcert.pemandartifacts/crypto/peerOrganizations/<instance-name>/signcert/<instance-name>-signcert.pem. - Copy the admin key from the admin credentials to
artifacts/crypto/ordererOrganizations/<instance-name>/keystore/<instance-name>-key.pemandartifacts/crypto/peerOrganizations/<instance-name>/keystore/<instance-name>-key.pem.
- Copy the admin certificate from the admin credentials to
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.
Create a Connection to an Oracle Blockchain Platform Instance
You must have a Blockchain Platform instance up and running to perform this step.
- In the VS Code Environments pane, click the Create Environment icon.
- On the Environments Details wizard:
- Enter the name for your remote environment.
- Enter a description.
- Browse to the directory where you've stored your connection profile from Oracle Blockchain Platform.
- Enter a user name and password with permissions to install, instantiate, and invoke chaincode.
- Click Test Login. This logs your profile into the remote network so that you can deploy to it.
- If you logged in successfully, click Create to save the profile.
Deploy Your Chaincode
- Select the chaincode project you want to deploy in the Chaincodes pane.
- In the Chaincode Details pane, select Deploy.
- 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.
- Click Deploy.
- 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 Deploy again - this will automatically perform the update for you.
- It has successfully upgraded the chaincode version.
- It has successfully installed the chaincode project.
- It has successfully instantiated the chaincode on each peer and the channel.
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 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.
- Select your chaincode project in the Chaincodes pane.
- Right-click and select Package.
- Select a location to save the package, and click Select Output Folder.
When the command completes successfully, the location of the package will be returned in the output.