IBM Blockchain Platform VSCode Extension

Pooja Kamat
4 min readDec 20, 2021

IBM blockchain platform VScode extension mainly helps us to create, test and debug Hyperledger Fabric smart contracts, it helps us connect to existing Hyperledger Fabric environments and as well create one locally with just a few clicks.

It helps build applications which transact on your blockchain network.

Lets walkthrough the steps and get going with the plugin :

Step 1: Plugin installation

As a first step launch VScode to install the plugin, click on view extensions and search for IBM blockchain platform and click on install.

Step 2: Pre — requisites

Once installed, the plugin requires a couple of pre-requisites installed for it to fully function as expected.

To check the list of pre-requisites we need to open the command palette, click shift+ctrl P, and type view pre-requisites.

This page will list all the required plugins, the ones installed and the ones which are not yet installed, or there may be a few pre-requisites which are present, but the plugin requires a higher version or a lower version.

Step 3: Setup network

Once the perquisites are installed, we can start using the plugin.

If the plugin was installed successfully, you will see an additional icon on left side, click on this.

The left side bar, contains views that shows Hyperledger Fabric resources.

The smart contracts will have a list of smart contract packages created.

The Fabric environments will contain the list of environments which we have set up. At a given time we can connect only to single environment.

Fabric gateways — this will list all the gateways, a gateway manages the network interactions on behalf of an application. Applications connect to a gateway and then all subsequent interactions are managed using that gateway’s configuration.

Fabric wallets — which will contain identities for various nodes on the network, gateway uses one of these identities to interact with the Hyperledger Fabric network.

There are 4 options provided to setup a fabric network.

1. Create new from template: This option will start a network locally. By default there are two templates embedded in the plugin:

a. Network comprising of single organization contributing single peer.

b. Network comprising of 2 organizations contributing one peer each.

The plugin downloads the images, starts containers, creates identities and channel.

2. Add an Ansible created network — Ansible is an open-source software which provides configuration management.

3. Add an IBM Blockchain Platform network — that is a network running on IBP cloud.

4. Add any other Fabric network- which takes node json files as inputs.

For the purpose of this blog will go ahead considering a local network setup.

Step 4: Start a network

To start a network, click on Fabric environments, this will give a list of all the available networks which have been setup.

We need to click on whichever network we have to connect, once connected will be notified about the same in bottom right corner as a notification.

The view then changes to show smart contracts, channels, nodes and organizations in local environment if we expand various sections.

That completes our network setup.

Step 5: Deploy smart contract

We can deploy smart contracts using one of the below ways :

a. Create New project — this will create a a new smart contract project for us, basically a skeleton structure. We can select language as per choice, that is Java, Javascript, Go or typescript.

b. Import a package — This will import an existing smart contract project with .cds extension.

c. Package open project — If we already have a smart contract project, use this option to open the project in current workspace.

Once added, will now package the smart contract.

We can directly click on instantiate and select the smart contract project, this one step, will package, install and instantiate smart contract.

Alternatively, we can do step by step as well :

  • Click on install- select the workspace which is created, enter name for the package, and the version.
  • Once installed this will show us in the list on left, click on instantiate. As we have a single peer in the n/w we can select default endorsement policy.

When instantiation completes, we can see the package under instantiated section.

Step 6: Invoke transaction

Before invoking transactions, we will add an identity, wallet and gateway.

Since we are using an inbuilt template, a gateway was already created for us.

Go to fabric gateway view, click on local network org1, this will ask for the identity using which the gateway will connect to the network.

Once connected, we will get a full view of channels and the smart contracts which are instantiated on that channel, along with the various transaction methods available to the application.

For a application to connect to a gateway, it requires connection profile which has details of the network and the wallet containing identity which will be used to interact with the gateway.

We can now see the smart contracts deployed, and the functions available to invoke. To invoke a transaction, right click on the function which has to be invoked.

Step 7: Upgrading an existing smart contract

Make changes to the contract.

Install the smart contract, increment the version and instantiate the package.

To instantiate right click and click on upgrade. Once upgraded, check the gateway, the newly created function will appear.

That completes deployment of smart contracts and invoking it, in addition the plugin also supports deployment of smart contracts which emit events, deployment of smart contracts with private data, generating sample test cases, debugging etc !

--

--