requestWriteContract method

  1. @override
Future requestWriteContract({
  1. required String? topic,
  2. required String chainId,
  3. required DeployedContract deployedContract,
  4. required String functionName,
  5. required Transaction transaction,
  6. List parameters = const [],
  7. String? method,
})
override

Implementation

@override
Future<dynamic> requestWriteContract({
  required String? topic,
  required String chainId,
  required DeployedContract deployedContract,
  required String functionName,
  required Transaction transaction,
  List<dynamic> parameters = const [],
  String? method,
}) async {
  if (_currentSession == null) {
    throw ReownAppKitModalException('Session is null');
  }
  if (!NamespaceUtils.isValidChainId(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'chainId should conform to "CAIP-2" format',
    ).toSignError();
  }
  if (transaction.from == null) {
    throw Errors.getSdkError(
      Errors.MALFORMED_REQUEST_PARAMS,
      context: 'transaction must include `from` value',
    ).toSignError();
  }
  //
  _appKit.core.logger.i(
    '[$runtimeType] requestWriteContract, chainId: $chainId',
  );

  try {
    final trx = Transaction.callContract(
      contract: deployedContract,
      function: deployedContract.function(functionName),
      from: transaction.from!,
      value: transaction.value,
      maxGas: transaction.maxGas,
      gasPrice: transaction.gasPrice,
      nonce: transaction.nonce,
      maxFeePerGas: transaction.maxFeePerGas,
      maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
      parameters: parameters,
    );

    return await request(
      topic: topic,
      chainId: chainId,
      request: SessionRequestParams(
        method: method ?? MethodsConstants.ethSendTransaction,
        params: [trx.toJson()],
      ),
    );
  } catch (e, s) {
    _appKit.core.logger.e(
      '[$runtimeType] requestWriteContract, error: $e, $s',
    );
    rethrow;
  }
}