callFunctionWithDeposit method
Future<Map>
callFunctionWithDeposit(
- String methodName,
- String methodArgs,
- Wallet wallet,
- double nearAmount,
- dynamic successURL,
- dynamic failureURL,
- dynamic approvalURL, [
- 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"};
}