Snippets

Beyondi d.o.o. ChaincodeA Invoke ChaincodeB

Created by Beyondi d.o.o. last modified
'use strict';
// SDK Library to asset with writing the logic
import { Context, Contract, Transaction } from 'fabric-contract-api';
// Business logic (well just util but still it's general purpose logic)
import { Iterators } from 'fabric-shim';

/**
 * Support the Updating of values within the SmartContract
 */
export class ChaincodeA extends Contract {

    @Transaction()
    public async init(ctx: Context) {
        console.info('============= Initialize ChaincodeA ===========');
    }

    // when doing Typescript, transaction decorator is required
    @Transaction()
    public async run(ctx: Context) {

        // this chaincode is on the same channel, first argument is chaincode name,
        // second is arguments: KEEP IN MIND, FIRST IS chaincode name, SECOD is args where args[0] is function name and the third is channel.
        const chaincodeResponse = await ctx.stub.invokeChaincode('ChaincodeB', ['weatherData'], 'ChannelB');

        // I added console.dir for you to investigate full response and then just a payload
        console.dir(chaincodeResponse);
        console.dir(chaincodeResponse.payload.toString('utf8'));
        return ctx.stub.getTxID();
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.