GithubHelp home page GithubHelp logo

chaincode-js's Introduction

Build Status

TypeScript/NodeJs chaincode scaffolding for Blockchain Starter Kit

This project contains the scaffolding necessary to create a Hyperledger Fabric based smart contract for NodeJs. The source code in the the project has been structured to integrate with the DevOps pipeline scripts created for our custom Blockchain Automation Toolchain based on the IBM Cloud Continuos Delivery Service. You can use this scaffolding as a starting point for your smart contract and connect it to the Blockchain Automation Toolchain to have it built, tested and deployed in a CI/CD fashion on the IBM Cloud.

Chaincode Development Instructions

This project is structured to support the development of multiple smart contracts that can be deployed as separate chaincode units into a Hyperledger Fabric network.

A sample smart contract can be found under the asset directory. This smart contract provides a starting point with the necessary transactions to create and update a simple asset. You can modify this smart contract with your own business logic, attributes and transactions.

Additional smart contracts can be developed and added under the chaincode directory. To create a new smart contract, create a new directory under chaincode and place the source code in the new directory i.e. chaincode/new-asset.

Notice that the purpose of this structure is to allow for the definition of multiple independent smart contracts that can easily be deployed separately by the Blockchain Automation Toolchain hence each smart contract should be self contained and self deployable.

Chaincode Deployment Instructions

When integrated with the Blockchain Automation Toolchain, the metadata specified in the deployment configuration file is used to indicate the smart contracts that must be deployed, the Hyperledger Fabric organizations that the smart contracts should be applied to and the channels where each smart contract should be instantiated.

The sample deployment configuration file provided in this project is as follows:

{
  "Org1MSP": {
    "chaincode": [
      {
        "name": "mycontract",
        "path": "chaincode/asset",
        "channels": [
          "mychannel"
        ],
        "instantiate": true,
        "install": true,
        "collections_config": "chaincode/asset/collections-config.json",
        "init_fn": "mycontract:method",
        "init_args": ["a","20"],
        "endorsement_policy": "{\"identities\":[{\"role\":{\"name\":\"member\",\"mspId\":\"Org1MSP\"}},{\"role\":{\"name\":\"member\",\"mspId\":\"Org2MSP\"}}],\"policy\":{\"1-of\":[{\"signed-by\":0},{\"signed-by\":1}]}}"
      }
    ]
  }
}

The simple structure of this file allows you to specify the following information:

  • Organization in which the smart contracts will be deployed. The organization must be represented by the MSP ID used by the organization in the Hyperledger Fabric network. In this sample we are installing smart contracts on peers for organization known as Org1MSP in the network. Notice that the Blockchain Automation Toolchain supports deploying smart contracts on multiple organizations. To install smart contracts in additional organizations, add a new element to the deployment configuration file e.g.

    {
        "Org1MSP": {
            ...
        },
        "Org2MSP": {
            ...
        }
    }
    
  • For every smart contract to be deployed an element describing the details of the smart contract should be added to the chaincode array. Notice that each element added to the array will be deployed as a separate smart contract in the Hyperledger Fabric network. For each smart contract created under the chaincode directory you should add at least one entry in the array.

  • The elements that describe a smart contract are as follows:

    • name: This is the name that will be used to deploy the smart contract.
    • path: Path of where the smart contract source can be found. This path is relative to the deployment configuration file.
    • channels: Comma separated string array containing the names of the channels where the smart contracts should be instantiated.
    • instantiate: Boolean indicating if the smart contract should be instantiated after installation.
    • install: Boolean indicating if the smart contract should be installed or not.
    • collections_config: (Optional) Configuration file path relative to the chaincode directory. This file dictates the name and the path of the Private Data Collection configuration.
    • endorsement_policy: (Optional) Custom endorsement policy that instructs a peer on how to decide whether a transaction is properly endorsed.
    • init_fn: (Optional) Method to be called when the chaincode is instantiated.
    • init_args: (Optional) Parameters required for the 'init_fn'.

Environment

We have successfully tested and deployed this scaffolding chaincode component on Hyperledger Fabric v1.4.4.

chaincode-js's People

Contributors

rolivieri avatar jt-nti avatar jorgedr94 avatar erin-hughes avatar eymorale avatar vandangogna avatar

Watchers

James Cloos avatar Michele Chilanti avatar  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.