convert static method

BigInt convert(
  1. BigInt value, {
  2. required Unit from,
  3. required Unit to,
})

Converts between units.

Example:

EthUnit.convert(BigInt.from(1), from: Unit.ether, to: Unit.gwei);
// Returns: 1000000000

Implementation

static BigInt convert(BigInt value, {required Unit from, required Unit to}) {
  // Convert to wei first
  final inWei = value * from.weiMultiplier;
  // Then convert to target unit
  return inWei ~/ to.weiMultiplier;
}