contract/sample/example02.js
/**
   * Query callback representing the query of a chaincode
   * @param {Context} stub 
   * @param {array} args 
   */
Query callback representing the query of a chaincode
@param {Context} stub
@param {array} args
Query callback representing the query of a chaincode @param { Context } stub @param { array } args
async query(stub, args) {
    if (args.length != 1) {
      throw new Error('Incorrect number of arguments. Expecting name of the person to query')
    }
    let jsonResp = {};
    let A = args[0];
    let Avalbytes = await stub.getState(A);
    if (!Avalbytes) {
      jsonResp.error = 'Failed to get state for ' + A;
      throw new Error(JSON.stringify(jsonResp));
    }
    jsonResp.name = A;
    jsonResp.amount = Avalbytes.toString();
    console.info('Query Response:');
    console.info(jsonResp);
    return Avalbytes;
  }
async query ( stub , args ) { if ( args . length != 1 ) { throw new Error ( 'Incorrect number of arguments. Expecting name of the person to query' ) } let jsonResp = { } ; let A = args [ 0 ] ; let Avalbytes = await stub . getState ( A ) ; if ( ! Avalbytes ) { jsonResp . error = 'Failed to get state for ' + A ; throw new Error ( JSON . stringify ( jsonResp ) ) ; } jsonResp . name = A ; jsonResp . amount = Avalbytes . toString ( ) ; console . info ( 'Query Response:' ) ; console . info ( jsonResp ) ; return Avalbytes ; }
Query callback representing the query of a chaincode
 @param {Context} stub
 @param {array} args
Query callback representing the query of a chaincode @param { Context } stub @param { array } args
// Get the state from the ledger