toBigInt static method
Converts a token amount to its smallest unit (BigInt) representation.
value
- The amount as a dynamic type.
decimals
- (Optional) The number of decimal places for the token, defaults to 18.
Returns the token amount in its smallest unit representation (BigInt).
Implementation
static BigInt toBigInt(dynamic value, [int decimals = 18]) {
if (value == null) throw Exception('Value was not defined');
final Decimal tokensAmountDecimal = Decimal.parse(value.toString());
final Decimal decimalsPow = Decimal.parse(pow(10, decimals).toString());
return BigInt.parse((tokensAmountDecimal * decimalsPow).toString());
}