call method

Future<Map> call(
  1. String caller,
  2. Contract contract,
  3. String funcName,
  4. List funcParams,
  5. String to, {
  6. BigInt? value,
  7. int gas = 0,
  8. String? gasPayer,
  9. String block = "best",
})

Call a contract method (read-only). This is a single transaction, single clause call. This WON'T create ANY change on blockchain. Only emulation happens. If function has any return value, it will be included in "decoded" field

Implementation

Future<Map> call(String caller, Contract contract, String funcName,
    List funcParams, String to,
    {BigInt? value,
    int gas = 0, // Note: value is in Wei
    String? gasPayer, // Note: gas payer of the tx
    String block = "best" // Target at which block
    }) async {
  // Get the Clause object
  var clause = this.clause(contract, funcName, funcParams, to, value: value);
  // Build tx body
  var needFeeDelegation = gasPayer != null;

  Map b = await getBlock();
  Map txBody = buildTxBody([clause.clause], await getChainTag(),
      calcBlockRef(b["id"]), calcNonce(),
      gas: gas, feeDelegation: needFeeDelegation);

  // Emulate the Tx
  List eResponses = await emulateTx(caller, txBody,
      block: block, gasPayer: gasPayer = gasPayer);
  // Should only have one response, since we only have 1 clause
  assert(eResponses.length == 1);

  // If emulation failed just return the failed response.
  if (anyEmulateFailed(eResponses)) {
    return eResponses[0];
  }

  return _beautify(eResponses[0], clause.contract!, clause.functionName!);
}