What is IBM blockchain platform visual studio code extension?
The IBM Blockchain Platform Visual Studio (VS) Code extension gives an environment within the VS Code for creating, packaging, and testing smart contracts. It was released on 5 May 2018. The latest version 1.0.14 was released on 24 Oct 2019. You can practice the extension to create your smart contract project and start generating your business logic. You can then practice the VS Code to test your smart contract on your local machine by using a preconfigured instance of Hyperledger Fabric before you deploy the smart contract to the IBM Blockchain Platform. Quite interesting!
Let’s discuss how fabric can be responsive through VS Code.
[Smart contract development]
Step 1: Install IBM Blockchain Platform VS Code Extension
Before you start to install the IBM Blockchain Platform VS Code extension, check prerequisites.
- Windows 10, Linux, or Mac OS are currently the supported OS.
- VS Code version 1.32 or higher.
- Docker version v17.06.2-ce or higher
- Docker Compose v1.14.0 or higher
- If you are developing Go smart contracts, you have to install Go version v1.12 or higher.
- If you are developing Node smart contracts, you have to install Node v8.x or v10.x and npm v6.x or higher
- If you are developing Java smart contracts, you need to install Java JDK v8.
- Go to the VS Code extension marketplace page or search for the IBM Blockchain Platform in the extensions panel within VS Code.
- Click to Install.
- Restart VS Code to complete the installation.
After the installation, you can see the IBM Blockchain icon on the left side of the VS Code to initiate the IBM Blockchain Platform panel.
Step 2: Set Up a Fabric Environment
Once you click on the icon(IBM Blockchain extension) you will get four following small box options:
- Smart contract
- Fabric environments
- Fabric gateway
- Fabric wallet
Now click on the local fabric option inside the fabric environment which will extract all necessary images and run it as a container. Once the connection is successful, you will observe a full fabric environment.
you can check your fabric environment using a docker ps command. If you have followed every installation dependency perfectly you will get the following output.
Step 3: Create a Smart Contract
You can use the extension to generate a new smart contract project in VS Code. The extension creates a basic smart contract that maintains an example asset in the language of your choice. You can use the structure of the model as a starting point for developing your business logic. The extension gives all the dependencies that are required to deploy your smart contract to an instance of Hyperledger Fabric.
- Click the IBM Blockchain icon to initiate the IBM Blockchain tab. Click the overflow menu in the smart contracts and click the Create New Project OR run ctrl+shift+p and click the Create New Project.
- After the successful creation of a smart contract, go through the lib folder and open the my-asset-contract.js file which is auto-generated. You can edit as per your business logic.
Step 4: Package a Smart Contract
You need to package a smart contract in .cds format before you can install it on the IBM Blockchain Platform network.
- Click the IBM Blockchain icon to initiate the IBM Blockchain tab.
- In the Smart Contracts, click the overflow menu and choose the Package Open Project.
Step 5: Deploy a Smart Contract to a Preconfigured Hyperledger Fabric Network
You can accept the VS Code to deploy your smart contract to a preconfigured Hyperledger Fabric network that the extension builds on your local machine. You can install, instantiate, and test your smart contract before you deploy it to a live network.
- Ensure docker is running
- In the Fabric Environments panel, click Install Smart Contract. Select the peer that you require to install the smart contract on. Select the smart contract package that you need to install, and click Install.
- In the Fabric Environments, click Instantiate Smart Contract. Select the installed smart contract to instantiate.
- Enter the name of the instantiate function in a smart contract. If you practiced the default smart contract template, no instantiate function is used. (optional)
If you adjusted your smart contract code and then repackaged it, you can upgrade the instantiated smart contract to deploy a newer version to the network.
After a smart contract is installed and instantiated, you can submit transactions to the functions inside a smart contract by using the Fabric Gateways panel and also using a node environment.
So in this blog, we had just done the key steps in the workflow of local smart contract development! You’ve generated a dummy contract, deployed it locally, and used it to submit transactions. Stay tuned!! Happy coding!!
Share via social media