requestReadContract method
Future<List>
requestReadContract({
- required String? topic,
- required String chainId,
- required DeployedContract deployedContract,
- required String functionName,
- EthereumAddress? sender,
- 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;
}
}