This repository provides samples to use for experimenting with Hyperledger Fabric. For this demo, you will use the following tools:
- Visual Studio Code: https://code.visualstudio.com/
- IBM Blockchain Platform: https://cloud.ibm.com/docs/blockchain?topic=blockchain-ibp-saas-pricing#ibp-saas-pricing-free. Use the free version for 30 days
- Follow these instructions to build your network: https://cloud.ibm.com/docs/blockchain?topic=blockchain-ibp-console-build-network
Smart Contracts are more easily deployed through the IBM Cloud Console, but, unfortunately, the default ordering service deploys with version 1.4 instead of 2.0. You will first need to correct this before deploying a smart contract on the IBM Cloud Console.
- Go to your IBM Blockchain Platform cloud console. Under nodes, click on Ordering Service, then click on Settings, and under Actions, click Channel Capabilities. Change the Orderer Capability and Channel Capability to version 2.0.0 and click Update Capabilities.
- You will now need to commit these changes. To do so, click on Channels --> Channel 1 and click Settings. a. Select the Org1 MSP and make sure to select the org1admin identity that will be used to update the channel. b. Continue clicking Next, accepting the defaults, until you get to Capabilities. Then update the Application, Orderer, and Channel Capabilities to 2.0.0. c. Continue clicking Next without any changes except specifying the Ordering Service Signature as the Ordering Service MSP. Then click Update Channel d. You will receive a notification to approve this update on the upper right-hand side of the application. Click Next to approve, and select the Ordering Service CA Admin. Then click to Approve. e. Then you will receive another notification to sign the channel configuration update. Select the Org1 MSP and admin identity org1admin to submit the channel update.
Follow these steps to deploy a smart contact onto your IBM Blockchain Platform channel.
In this step, you will use Visual Studio Code. Then search the Marketplace for IBM Blockchain Platform and install the extension. Click on the icon shown in the following figure shown in the following figure:
Open the fabcar directory in VS Code. This is an example smart contract from the IBM samples that you can install on your Blockchain Channel.
From the VS Code Extension for the IBM Blockchain, you will only use the Smart Contracts. Click to Package Open Project as shown in the following image:
When prompted during packaging, select tar.gz (V2 channel capabilities). Once the packaging completes, you should see the asset you created (e.g., fabcar.tar.gz)). Click to export this tar.gz file. The file will be used in the next step.
Go back to your cloud IBM Blockchain Platform and click on Channels --> channel1 (Ordering Service). Note, that the primary tools menu also has a Smart Contracts menu item, but this will not work. It's for an older version of Hyperledger Fabric.
In the channel, click to Propose smart contract definition. Then select the organization (i.e., Org1 MSP), and make sure to use a valid admin identity. This will need to be a user with the type Admin (i.e., org1admin). From here, upload the smart contract (i.e., fabcar.tar.gz) from step 1. Accept all defaults and then click Propose.
At this point, the contract is proposed to the channel, but each organization that's a part of the channel needs to commit the smart contract. If you use the sample scenario, this will only be Org1.
Still from the Channels --> channel1 (Ordering Service), click on the new smart contract and go through the steps to deploy the contract for Org1. Once this has successfully deployed, you should be able to see the new contract on the organization's peer. You are now ready to use the smart contract!
Before invoking the smart contract, you'll need both a gateway definition and a user file in your wallet. First, to get the gateway definition, go back to the cloud IBM Blockchain Platform, and click on Organizations --> Org1 MSP. Click to Create connection profile.
Here you will select the peers to include (e.g., Peer1 in the simple example) and keep the Include Org1 CA checked. Click, to Download connection profile and save this file under the gateway directory. Make sure to call this file org1msp_profile.json
.
To begin testing the invocation, use the code in cars-test. Open this directory in VS-Code and run npm install
from the terminal. You will first want to run enrollUser.js (e.g., node enrollUser.js
), but before running this, you'll need to substitute the address for ccp.certificateAuthorities
. Open org1msp_profile.json
in a text editor, and find certificateAuthorities
for organizations --> org1msp. In enrollUser.js, replace 169.51.205.58:30181
with what you find from the connection profile. Now, you should be able to run enrollUser.js without any issue.
Finally, you can use app.js to test the invocation of your smart contract. Make sure to perform the same certificateAuthorities
replacement that you did for enrollUser.js.