callFunctionWithDeposit method

Future<Map> callFunctionWithDeposit(
  1. String methodName,
  2. String methodArgs,
  3. Wallet wallet,
  4. double nearAmount,
  5. dynamic successURL,
  6. dynamic failureURL,
  7. dynamic approvalURL, [
  8. int gasFees = Constants.defaultGas,
])

Implementation

Future<Map<dynamic, dynamic>> callFunctionWithDeposit(
    String methodName,
    String methodArgs,
    Wallet wallet,
    double nearAmount,
    successURL,
    failureURL,
    approvalURL,
    [int gasFees = Constants.defaultGas]) async {
  AccessKey accessKey = await callerAccount.findAccessKey();

  // Create Transaction
  accessKey.nonce++;
  String publicKey =
      KeyStore.publicKeyToString(callerAccount.keyPair.publicKey);

  Transaction transaction = Transaction(
      actionType: ActionType.functionCall,
      signer: callerAccount.accountId,
      publicKey: publicKey,
      nearAmount: nearAmount.toStringAsFixed(12),
      gasFees: gasFees,
      receiver: contractId,
      methodName: methodName,
      methodArgs: methodArgs,
      accessKey: accessKey);
  // Serialize Transaction
  Uint8List serializedTransaction =
      TransactionManager.serializeFunctionCallTransaction(transaction);

  // Sign with wallet if there is a deposit
  String transactionEncoded =
      TransactionManager.encodeSerialization(serializedTransaction);
  wallet.requestDepositApproval(
      transactionEncoded, successURL, failureURL, approvalURL);
  return {"Result": "Please follow wallet to approve transaction"};
}