Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fabric-contract-api

Package Overview
Dependencies
Maintainers
1
Versions
221
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fabric-contract-api

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

  • 1.3.0-snapshot.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-15.01%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

Version Build Status

The fabric-contract-api provides the contract interface. a high level API for application developers to implement Smart Contracts. Within Hyperledger Fabric, Smart Contracts are also known as Chaincode. Working with this API provides a high level entry point to writing business logic. (this contract interface is new in version 1.3)

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

Contract Interface

Installation

npm install --save fabric-contract-api

Usage

Implement a class that ends the contract class, a contsturctor is needed. The other functions will be invokable functions of your Smart Contract

// updatevalues.js
'use strict';

// SDK Library to asset with writing the logic
const { Contract } = require('fabric-contract-api');

// Business logic (well just util but still it's general purpose logic)
const util = require('util');

/**
 * Support the Updating of values within the SmartContract
 */
class UpdateValuesContract extends Contract

    constructor(){
		super('org.mynamespace.updates');
	}

	async transactionA(ctx, newValue) {
		// retrieve existing chaincode states
		let oldValue = await ctx.stub.getState(key);

		await ctx.stub.putState(key, Buffer.from(newValue));

		return Buffer.from(newValue.toString());
	}

	async transactionB(ctx) {
	  //  .....
	}

};

module.exports = UpdateValuesContract

As with standard node modules make sure that this class is exported as follows.

// index.js
'use strict';

const UpdateValues = require('./updatevalues')
module.exports.contracts = ['UpdateValues'];

Note: In order to make this contract runnable in version 1.3, also install the fabric-shim module as below, and ensure that the 'start' script in package.json refers to startChaincode

  "scripts": {
	"start": "startChaincode"
  }

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.

Keywords

FAQs

Package last updated on 30 Aug 2018

Did you know?

Socket

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc