epezhman-fabric-shim-2
TypeScript icon, indicating that this package has built-in type declarations

1.4.4 • Public • Published

NPM

Version Build Status

The fabric-shim provides the chaincode interface, a lower level API for implementing "Smart Contracts". To confirm that this is the same as the fabric-shim in previous versions of Hyperledger Fabric.

Detailed explanation on the concept and programming model can be found here: http://hyperledger-fabric.readthedocs.io/en/latest/chaincode.html.

Chaincode Interface

Installation

npm install --save fabric-shim

Usage

The chaincode interface contains two methods to be implemented:

const shim = require('fabric-shim');
 
const Chaincode = class {
    async Init(stub) {
        // use the instantiate input arguments to decide initial chaincode state values
 
        // save the initial states
        await stub.putState(key, Buffer.from(aStringValue));
 
        return shim.success(Buffer.from('Initialized Successfully!'));
    }
 
    async Invoke(stub) {
        // use the invoke input arguments to decide intended changes
 
        // retrieve existing chaincode states
        let oldValue = await stub.getState(key);
 
        // calculate new state values and saves them
        let newValue = oldValue + delta;
        await stub.putState(key, Buffer.from(newValue));
 
        return shim.success(Buffer.from(newValue.toString()));
    }
};

Start the chaincode process and listen for incoming endorsement requests:

shim.start(new Chaincode());

API Reference

Visit fabric-shim.github.io and click on "Classes" link in the navigation bar on the top to view the list of class APIs.

Support

Tested with node.js 8.9.0 (LTS).

License

This package is distributed under the Apache License, Version 2.0, see LICENSE.txt for more information.

Package Sidebar

Install

npm i epezhman-fabric-shim-2

Weekly Downloads

1

Version

1.4.4

License

Apache-2.0

Unpacked Size

490 kB

Total Files

47

Last publish

Collaborators

  • epezhman