contract/sample/example02.js
/**
   * Initialize the chaincode
   * @param {Context} stub 
   */
Initialize the chaincode
@param {Context} stub
Initialize the chaincode @param { Context } stub
async Init(stub) {
    console.info('========= example02 Init =========');
    let ret = stub.getFunctionAndParameters();
    console.info(ret);
    let args = ret.params;
    if (args.length != 4) {
      return shim.error('Incorrect number of arguments. Expecting 4');
    }
    let A = args[0];
    let B = args[2];
    let Aval = args[1];
    let Bval = args[3];
    if (typeof parseInt(Aval) !== 'number' || typeof parseInt(Bval) !== 'number') {
      return shim.error('Expecting integer value for asset holding');
    }
    try {
      await stub.putState(A, Buffer.from(Aval));
      try {
        await stub.putState(B, Buffer.from(Bval));
        return shim.success();
      } catch (err) {
        return shim.error(err);
      }
    } catch (err) {
      return shim.error(err);
    }
  }
async Init ( stub ) { console . info ( '========= example02 Init =========' ) ; let ret = stub . getFunctionAndParameters ( ) ; console . info ( ret ) ; let args = ret . params ; if ( args . length != 4 ) { return shim . error ( 'Incorrect number of arguments. Expecting 4' ) ; } let A = args [ 0 ] ; let B = args [ 2 ] ; let Aval = args [ 1 ] ; let Bval = args [ 3 ] ; if ( typeof parseInt ( Aval ) !== 'number' || typeof parseInt ( Bval ) !== 'number' ) { return shim . error ( 'Expecting integer value for asset holding' ) ; } try { await stub . putState ( A , Buffer . from ( Aval ) ) ; try { await stub . putState ( B , Buffer . from ( Bval ) ) ; return shim . success ( ) ; } catch ( err ) { return shim . error ( err ) ; } } catch ( err ) { return shim . error ( err ) ; } }
Initialize the chaincode
 @param {Context} stub
Initialize the chaincode @param { Context } stub
// initialise only if 4 parameters passed.