tokenSupply method Null safety

Future<EtherScanSupplyModel> tokenSupply (
  1. {String? tokenName,
  2. String? contractAddress}
)

Returns the supply of Tokens

tokenname - Name of the Token

contractaddress - Address from token contract

Example

var supply = eth.tokenSupply(
    tokenname: null,
    contractAddress: '0x57d90b64a1a57749b0f932f1a3395792e12e7055'
);

Result returned in Wei, to get value in Ether divide resultAbove/1000000000000000000)

Implementation

Future<EtherScanSupplyModel> tokenSupply({
  String? tokenName,
  String? contractAddress,
}) async {
  const module = 'stats';
  const action = 'tokensupply';

  Map<String, dynamic>? query = {
    'module': module,
    'action': action,
    'apiKey': apiKey,
  };

  if (tokenName != null) {
    query.putIfAbsent('tokenname', () => tokenName);
  }

  if (contractAddress != null) {
    query.putIfAbsent('contractaddress', () => contractAddress);
  }

  return (await get(query)).fold(
    (l) => EtherScanSupplyModel.empty(),
    (r) => EtherScanSupplyModel.fromJson(r),
  );
}