Socket
Socket
Sign inDemoInstall

fabric-shim

Package Overview
Dependencies
132
Maintainers
3
Versions
301
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fabric-shim

A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other


Version published
Weekly downloads
22K
decreased by-3.62%
Maintainers
3
Install size
31.8 MB
Created
Weekly downloads
 

Changelog

Source

v2.5.4

Wed 14 Jun 2023 12:29:35 BST

  • 690c91a9 Using the CLI provided gRPC configurations when starting the chaincode (#401)
  • cf179e7b Update SetEvent documentation (#399)
  • 6f66124b Update COMPATIBILITY.md for Node 18. (#396)

Readme

Source

NPM

Version

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: https://hyperledger-fabric.readthedocs.io/en/latest/smartcontract/smartcontract.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 API Reference 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.

Keywords

FAQs

Last updated on 16 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc