1.1.14 • Published 5 years ago

node-ledger-client v1.1.14

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

node-ledger-client

Hyperledger client based on Hyperledger fabric sdk node now supports version 1.3 of Hyperledger Fabric.

Usage

Import in your Typescript file:

import { LedgerClient } from 'node-ledger-client';

Now you can view a 3 functions to working with chaincode: 1. async doInvoke(fcn: string, args: string[]) 2. async doQuery(fcn: string, args: string[]) 3. async registerChaincodeEvent(chaincodeId: string, peerName: string, eventName: string, onEvent, onError)

async doInvoke

The Invoke method is invoked whenever the state of the blockchain is queried or modified. <br

This method needs two arguments, the first is the name of the function we want to invoke in the chaincode. The second is the array of args that we want to pass to the chaincode function. doInvoke returns a Promise. Example const payload = await ledgerClient.doInvoke(fcn , args);

async doQuery

A chaincode query is somewhat simpler to implement as it involves the entire network, but simply requires communication from client to peer.

It is the same seen just before. Example const payload = await ledgerClient.doQuery(fcn , args);

async registerChaincodeEvent

const config = require('./config-fabric-network.json');
const ledgerClient = await LedgerClient.init(config); 
const invoke = ledgerClient.doInvoke('storeProcessStepRouting', ['test']);

const peerName = config.organizations[0].peers[0].name;
const ccid = config.chaincode.name;
const eventId = "EVENT"; //eventName
let handler = null;
async function main() {
    async function chaincodeEventSubscribe(eventId: string, peerName: string) {
        return ledgerClient.registerChaincodeEvent(ccid, peerName, eventId, (event) => {
            console.log('Event arrived with name: ' + event.event_name + ' and with payload ' + Buffer.from(event.payload));
        }, (err) => {
            console.log('Errore ricevuto nell evento' + err);
            setTimeout(() => {
                chaincodeEventSubscribe(eventId, peerName).then((handler) => {
                    console.log('Handler received ' + JSON.stringify(handler));
                }, (err) => {
                    console.error('Handler received ' + err);
                });
            }, 1000);
        });
    }
    chaincodeEventSubscribe(eventId, peerName).then((handle) => {
        console.log('Handler received ' + JSON.stringify(handle));
        handler = handle;
    }, (err) => {
        console.error('Handler received ' + err);
    });
}
main();

Watch out!!! The string eventName must be the same as the event created in the chaincode!!!

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago