requestReadContract method

  1. @override
Future<List> requestReadContract({
  1. required String? topic,
  2. required String chainId,
  3. required DeployedContract deployedContract,
  4. required String functionName,
  5. EthereumAddress? sender,
  6. List parameters = const [],
})
override

Implementation

@override
Future<List<dynamic>> requestReadContract({
  required String? topic,
  required String chainId,
  required DeployedContract deployedContract,
  required String functionName,
  EthereumAddress? sender,
  List parameters = const [],
}) async {
  if (_currentSession == null) {
    throw ReownAppKitModalException('Session is null');
  }
  String reqChainId = chainId;
  final isValidChainId = NamespaceUtils.isValidChainId(chainId);
  if (!isValidChainId) {
    if (selectedChain!.chainId == chainId) {
      reqChainId = '${CoreConstants.namespace}:$chainId';
    } else {
      throw Errors.getSdkError(
        Errors.UNSUPPORTED_CHAINS,
        context: 'chainId should conform to "CAIP-2" format',
      );
    }
  }
  //
  _logger.d('[$runtimeType] requestWriteContract, chainId: $reqChainId');

  final networkInfo = ReownAppKitModalNetworks.getNetworkById(
    reqChainId.split(':').first,
    reqChainId.split(':').last,
  )!;

  try {
    if (selectedChain == null) {
      throw ReownAppKitModalException(
        'You must select a chain before reading a contract',
      );
    }
    return await _appKit.requestReadContract(
      deployedContract: deployedContract,
      functionName: functionName,
      rpcUrl: networkInfo.rpcUrl,
      sender: sender,
      parameters: parameters,
    );
  } catch (e) {
    rethrow;
  }
}