How to use IBM Blockchain Visual Studio Code extension to connect to IBM Blockchain Platform

Vandan Gogna
4 min readNov 26, 2019

--

I. Description

Using the VScode plugin, a developer can complete the following tasks easily and avoid the tedious and manual steps that are time consuming and error prone, in turn providing a quick and efficient development experience.

a. Create a smart contract

b. Import /generate a package that can be deployed on an HLF environment

c. Deploy an existing smart contract

The plugin allows the HLF developer to save significant amount of time and effort when it comes to chaincode development and testing it against IBM Blockchain Platform. A developer can choose between languages such as Golang and the ones supported by the Java Virtual Machine and Node.js runtimes like Java, JavaScript, TypeScipt to write the smart contract. The developer can then use the VS code plugin to deploy (local fabric instance only) the smart contract and then test to verify all the functionality. Currently the VS code plugin only allows query or invoke transactions on IBM Blockchain platform.

Having the ability to connect the VScode plugin to IBP and invoke transactions allows one to quickly test against an actual blockchain network and see the results executed by your chaincode. This is particularly helpful during the development cycle when diagnosing a problem or doing general sanity testing/verification.

II. Requirements

1) How to install the VScode plugin:

https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform

2) For detailed steps on how to create a new smart contract project using VScode plugin:

https://developer.ibm.com/tutorials/ibm-blockchain-platform-vscode-smart-contract/

3) How to deploy a smart contract on IBP:

III. Steps to execute

1. Pre-requisites — VS code plugin and an available IBPv2 instance (see above section II)

2. Download connection profile for Org1:

https://cloud.ibm.com/docs/services/blockchain?topic=blockchain-ibp-console-app#ibp-console-app-profile

3. Download JSON peer admin identity file, you must use the correct identity from the following step while setting up the IBP instance.

https://cloud.ibm.com/docs/services/blockchain?topic=blockchain-ibp-console-identities#ibp-console-identities-enroll

4. Generate public certificate and private key from the base64 encoded values from the identity file used above. The identity’s public certificate and private key can be obtained using 2 ways :

a. Using nodeJS — Buffer.from(‘string_to_be_decoded’, ‘base64’).toString()

b. Using command line — https://cloud.ibm.com/docs/services/blockchain?topic=blockchain-ibp-console-identities#ibp-console-identities-expiration

5. Save the public certificate and the private key for use in the next step.

6. Select IBM Blockchain platform extension in vs code.

7. Under `Fabric Wallets`, create a new wallet by clicking on `+` sign

a. Choose `Create a new wallet and add an identity`.

b. Provide a name for this new wallet (Ex: IbpConnectionWallet).

c. Provide a new for the Identity (Ex: org1admin).

d. Enter the MSPID for the associated org (Ex: Org1MSP).

e. Select `Provide certificate and private key files` — this comes from step 4 in the section above

i. Browse for the public certificate file in pem format

ii. Browse for the private key file in pem format.

f. A new wallet should now be visible under `Fabric Wallets` section.

8. Under `Fabric Gateways` create a new gateway by clicking on the `+` sign.

a. Select `Create a gateway from a connection profile`

b. Enter a name for the new gateway (Ex: IBP-conn-gateway)

c. Browse for the connection profile (from step 2 from section above)

d. The new gateway should now appear under `Fabric Gateways`.

9. Click on the new\existing fabric gateway you want to use:

a. Select the new\existing wallet associated with that IBPv2 instance.

b. The gateway should successfully connect to specific instance of IPBv2

c. You should now see:

i. Connected use id to IBPv2

ii. Channel(s)

iii. Expand channel(s) and see the available chaincode(s) installed on the channel(s)

10. Once you see the available chaincode(s) you can perform Query operation:

a. Right click on the chaincode and select Evaluate transaction (READONLY).

b. Provide the method name.

c. Optional — Provided any required parameters.

11. Once you see the available chaincode(s) you can perform Invoke operation:

a. Right click on the chaincode and select Submit transaction.

b. Provide the method name.

c. Optional — Provided any required parameters.

In conclusion, as a HLF developer the VS code plugin has been an invaluable tool for me which allows me to deliver and hopefully it will provide the same value to anyone developing smart contracts.

**NOTES:

1. VS code refers to Visual Studio code

2. Plugin refers to IBM Blockchain platform extension

3. VSCode plugin currently does not support chaincode installation and instantiation on IBM Blockchain platform.

4. HLF refers to Hyperledger Fabric

5. VSCode refers to Visual Studio Code

Bring your plan to the IBM Garage.
Are you ready to learn more about working with the IBM Garage? We’re here to help. Contact us today to schedule time to speak with a Garage expert about your next big idea. Learn about our IBM Garage Method, the design, development and startup communities we work in, and the deep expertise and capabilities we bring to the table.

Schedule a no-charge visit with the IBM Garage.

--

--