This document has been prepared by Kemal Aydin (kemal.aydin@ibm.com) and Yigit Polat (yigit.polat@ibm.com), and contains a visual description of IBM Blockchain Platform Extension for VS Code and its capabilities as well as providing comprehensive content to whom demands hands-on trainings.
The IBM Blockchain Platform Visual Studio (VS) Code extension provides an enviroment to develop, test, and debug their smart contracts. Moreover, it brings ease to developers to deploy their smart contracts to preconfigured Hyperledger Fabric network on their local machines.
The screenshots in this guide were taken from an Ubuntu Virtual Machine which contains all the required tools and configurations. If you would like to follow the steps, don't hesitate to contant to document owners to get the VM image.
- Package a Smart Contract Project
- Deploy a Local Hyperledger Fabric Network
- Install and Instantiate the Smart Contract
- Setting Up Hyperledger Fabric SDK for Node.js
- Launch VS Code from the menu bar.
- Click the Open Folder button to add project to the workspace.
- Navigate to the folder given in the above screenshot and click OK button.
- lib/fabcar.js file is the smart contract (chaincode) that will be deployed in Hyperledger Fabric network.
- This smart contract is written in JavaScript.
- Navigate to the IBM Blockchain Platform panel from the sidebar.
- In the Smart Contract Packages pane, click the overflow menu and select Package a Smart Contract Project.
- See the success message from the buttom right corner and packaged smart contract under the Smart Contract Packages pane as .cds format.
- In the Local Fabric Ops pane, click the overflow menu and select Start Fabric Runtime. This will create a basic Fabric network with one orderer, one peer, and one certificate authority.
- See that Local Fabric Ops pane changes to show Smart Contracts, Channels, Nodes and Organizations.
- Double-click local_fabric in the Fabric Gateways pane to connect to the local network. By default, the connection uses the admin identity in the Fabric wallets pane.
- The VS Code extention uses Docker Compose to launch our various Fabric component containers behind the scenes. Open a new Terminal window and type the following commands to see the running Docker Containers and Docker Images that needed to run the Fabric components.
docker ps -a
docker images
- Click on the Install button under the LOCAL FABRIC OPS pane.
- You will be prompted to select which version of your chaincode is going to be installed.
- You can have multiple version of your chaincode
- You can upgrade or downgrade of your chaincode's version.
- You will see the installed chaincode and its version under the LOCAL FABRIC OPS pane.
- If you keep waiting cursor on the installed chaincode, you will see the peer(s) that contains installed chaincode.
- You will see the message that indicates process' result.
- This could be positive message or vice versa.
- Click on the Instantiate button under the LOCAL FABRIC OPS pane.
- You will be prompted to select which version of your chaincode is going to be instantiated.
- If you don't have any installed chaincode, you will be prompted to select which version of your chaincode is going to be installed. After that, you will be prompted to instantiate.
- You can have multiple version of your chaincode
- You can upgrade or downgrade of your chaincode's version.
- You will be prompted to select which function of your chaincode is going to be called during instantiation process.
- This step is optional. If you want to set some initial values, you can use this function.
- You will be prompted to specify which parameter(s) is going to be passed during instantiation process.
- This step is optional. If you specify a function that is called during instantiation process (step 4), you can pass some arguments for that function.
- You will be prompted to browse your collection configuration file if your smart contract uses private data.
- You will see the instantiated chaincode and its version under the LOCAL FABRIC OPS pane.
- If you keep waiting cursor on the instantiated chaincode, you will see the channel that contains instantiated chaincode.
- You will see the message that indicates process' result.
- This could be positive message or vice versa.
- Click on the mychannel button under the FABRIC GATEWAYS pane.
- You will see the functions that are found in instantiated chaincode.
- Right click on the queryAllCars method under the mychannel tab, select the Evaluate Transaction option.
- Evaluate Transaction is used to query blockchain network, Submit Transaction is used to invoke blockchain network.
- You will be prompted to specify which parameter(s) is going to be passed to the selected function.
- Multiple parameter can be passed at once.
- You will be prompted to specify transient data for the transaction.
- You will see the result in OUTPUT tab.
- The results are set during instantiation process in step 4.
- Right click on the queryCar method under the mychannel tab, select the Evaluate Transaction option.
- You will be prompted to specify which parameter(s) is going to be passed to the selected function.
- You will be prompted to specify transient data for the transaction.
- You will see the result in OUTPUT tab.
- Right click on the changeCarOwner method under the mychannel tab, select the Submit Transaction option.
- You will be prompted to specify which parameter(s) is going to be passed to the selected function.
- You will be prompted to specify transient data for the transaction.
- You will see the result in OUTPUT tab.
- Right click on the queryCar method under the mychannel tab, select the Evaluate Transaction option.
- You will be prompted to specify which parameter(s) is going to be passed to the selected function.
- You will be prompted to specify transient data for the transaction.
- You will see the result in OUTPUT tab.
- Right click on the peer0.org1.example.com under the Nodes tab, select the Export Connection Profile option.
- Choose the right path, entitle the file as local_fabric_connection.json and click on the Export button.
- Clink on the Close Folder button.
- Clink on the Open Folder button.
- Choose the right path and click on the OK button.
- Click on the local_fabric_connection.json file on the left pane.
- Click on the Terminal and open a new terminal by clicking on New Terminal button.
- Click on the enrollAdmin.js file on the left pane.
- Ensure that present/current working directory is ~/Desktop/fabcar/javascript.
- Type "node enrollAdmin.js". You will see the result in TERMINAL tab.
- Click on the registerUser.js file on the left pane.
- Ensure that present/current working directory is ~/Desktop/fabcar/javascript.
- Type "node registerUser.js". You will see the result in TERMINAL tab.
- You will see the credentials for admin and user1 in the wallet directory on the left pane.
- Click on the invoke.js file on the left pane.
- Ensure that present/current working directory is ~/Desktop/fabcar/javascript.
- Type "node invoke.js". You will see the result in TERMINAL tab.
- Click on the query.js file on the left pane.
- Ensure that present/current working directory is ~/Desktop/fabcar/javascript.
- Type "node query.js". You will see the result in TERMINAL tab.
- Click on the IBM Blockchain Platform Extension on the left pane.
- Click on the triple dot and select Teawdown Fabric Runtime option.
- Click on the Yes button on the message window.