getTokenInfo function
Implementation
Future<TokenInfo?> getTokenInfo({
required String contractAddress,
required EvmRpcInterface rpc,
}) async {
final tokenContract = ERC20Contract(
contractAddress: contractAddress,
rpc: rpc,
);
try {
final result = await Future.wait(
[
tokenContract.getDecimals(),
tokenContract.getName(),
tokenContract.getSymbol(),
tokenContract.getSupply(),
],
eagerError: true,
);
int decimals = result[0] as int;
String name = result[1] as String;
String symbol = result[2] as String;
BigInt maxSupply = result[3] as BigInt;
double maxSupplyDouble = maxSupply.toDouble() / pow(10, decimals);
return TokenInfo(
decimals: decimals,
maxSupply: maxSupplyDouble,
symbol: symbol,
name: name,
contractAddress: contractAddress,
);
} catch (e) {
return null;
}
}