GithubHelp home page GithubHelp logo

kemallaydin / ibm-blockchain-platform-extension-for-vs-code Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 10.57 MB

The IBM Blockchain Platform Visual Studio (VS) Code extension provides an environment 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.

License: Apache License 2.0

ibm ibm-cloud ibm-blockchain-platform vscode hyperledger hyperledger-fabric chaincode smart-contracts docker

ibm-blockchain-platform-extension-for-vs-code's Introduction

IBM Blockchain Platform Extension for VS Code Tutorial

This document has been prepared by Kemal Aydin ([email protected]) and Yigit Polat ([email protected]), 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.

Table of Contents

  1. Package a Smart Contract Project
  2. Deploy a Local Hyperledger Fabric Network
  3. Install and Instantiate the Smart Contract
  4. Setting Up Hyperledger Fabric SDK for Node.js

1. Package a Smart Contract Project

Step 1.1

Launch VS Code

  • Launch VS Code from the menu bar.

Step 1.2

Open Folder

  • Click the Open Folder button to add project to the workspace.

Step 1.3

Select Folder

  • Navigate to the folder given in the above screenshot and click OK button.

Step 1.4

Project

  • lib/fabcar.js file is the smart contract (chaincode) that will be deployed in Hyperledger Fabric network.
  • This smart contract is written in JavaScript.

Step 1.5

IBP

  • Navigate to the IBM Blockchain Platform panel from the sidebar.

Step 1.6

Package

  • In the Smart Contract Packages pane, click the overflow menu and select Package a Smart Contract Project.

Step 1.7

Package

  • See the success message from the buttom right corner and packaged smart contract under the Smart Contract Packages pane as .cds format.

2. Deploy a Local Hyperledger Fabric Network

Step 2.1

Start Fabric Runtime

  • 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.

Step 2.2

Local Fabric OPS

  • 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.

Step 2.3

Docker

  • 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

3. Install and Instantiate the Smart Contract

Step 3.1

install-chaincode#1

  • 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.

Step 3.2

install-chaincode#2

  • 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.

Step 3.3

instantiate-chaincode#1

  • 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.

Step 3.4

instantiate-chaincode#2

  • 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.

Step 3.5

instantiate-chaincode#3

  • 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.

Step 3.6

instantiate-chaincode#4

  • You will be prompted to browse your collection configuration file if your smart contract uses private data.

Step 3.7

instantiate-chaincode#5

  • 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.

Step 3.8

instantiate-chaincode#6

  • Click on the mychannel button under the FABRIC GATEWAYS pane.
    • You will see the functions that are found in instantiated chaincode.

Step 3.9

instantiate-chaincode#7

  • 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.

Step 3.10

instantiate-chaincode#8

  • 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.

Step 3.11

instantiate-chaincode#9

  • You will be prompted to specify transient data for the transaction.

Step 3.12

instantiate-chaincode#10

  • You will see the result in OUTPUT tab.
    • The results are set during instantiation process in step 4.

Step 3.13

instantiate-chaincode#11

  • Right click on the queryCar method under the mychannel tab, select the Evaluate Transaction option.

Step 3.14

instantiate-chaincode#12

  • You will be prompted to specify which parameter(s) is going to be passed to the selected function.

Step 3.15

instantiate-chaincode#13

  • You will be prompted to specify transient data for the transaction.

Step 3.16

instantiate-chaincode#14

  • You will see the result in OUTPUT tab.

Step 3.17

instantiate-chaincode#15

  • Right click on the changeCarOwner method under the mychannel tab, select the Submit Transaction option.

Step 3.18

instantiate-chaincode#16

  • You will be prompted to specify which parameter(s) is going to be passed to the selected function.

Step 3.19

instantiate-chaincode#17

  • You will be prompted to specify transient data for the transaction.

Step 3.20

instantiate-chaincode#18

  • You will see the result in OUTPUT tab.

Step 3.21

instantiate-chaincode#19

  • Right click on the queryCar method under the mychannel tab, select the Evaluate Transaction option.

Step 3.22

instantiate-chaincode#20

  • You will be prompted to specify which parameter(s) is going to be passed to the selected function.

Step 3.23

instantiate-chaincode#21

  • You will be prompted to specify transient data for the transaction.

Step 3.24

instantiate-chaincode#22

  • You will see the result in OUTPUT tab.

4. Setting Up Hyperledger Fabric SDK for Node.js

Step 4.1

hyperledger-fabric-sdk#1

  • Right click on the peer0.org1.example.com under the Nodes tab, select the Export Connection Profile option.

Step 4.2

hyperledger-fabric-sdk#2

  • Choose the right path, entitle the file as local_fabric_connection.json and click on the Export button.

Step 4.3

hyperledger-fabric-sdk#3

  • Clink on the Close Folder button.

Step 4.4

hyperledger-fabric-sdk#4

  • Clink on the Open Folder button.

Step 4.5

hyperledger-fabric-sdk#5

  • Choose the right path and click on the OK button.

Step 4.6

hyperledger-fabric-sdk#6

  • Click on the local_fabric_connection.json file on the left pane.

Step 4.7

hyperledger-fabric-sdk#7

  • Click on the Terminal and open a new terminal by clicking on New Terminal button.

Step 4.8

hyperledger-fabric-sdk#8

  • 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.

Step 4.9

hyperledger-fabric-sdk#9

  • 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.

Step 4.10

hyperledger-fabric-sdk#10

  • 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.

Step 4.11

hyperledger-fabric-sdk#11

  • 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.

Step 4.12

hyperledger-fabric-sdk#12

  • Click on the IBM Blockchain Platform Extension on the left pane.
  • Click on the triple dot and select Teawdown Fabric Runtime option.

Step 4.13

hyperledger-fabric-sdk#13

  • Click on the Yes button on the message window.

References

License

Apache License 2.0

ibm-blockchain-platform-extension-for-vs-code's People

Contributors

kemallaydin avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.