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');
  }
  if (!NamespaceUtils.isValidChainId(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'chainId should conform to "CAIP-2" format',
    ).toSignError();
  }
  //
  _appKit.core.logger.i(
    '[$runtimeType] requestReadContract, chainId: $chainId',
  );

  final namespace = NamespaceUtils.getNamespaceFromChain(chainId);
  final id = ReownAppKitModalNetworks.getIdFromChain(chainId);
  final networkInfo = ReownAppKitModalNetworks.getNetworkInfo(namespace, id)!;

  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;
  }
}