Skip to content

@lelantos-org/sdk / protocol / toCircuitUnits

Function: toCircuitUnits() ​

ts
function toCircuitUnits(
   tokenAmount, 
   scale, 
   opts?
): CircuitAmount;

Defined in: @lelantos-org/sdk/dist/protocol/units.d.ts:96

ERC-20 base units → circuit units.

round picks what happens off a unit boundary:

  • "exact" (default) throws. Use wherever an off-boundary amount is a mistake; at a fixed scale nothing finer is representable, and truncating would silently short the caller.
  • "down" floors, dropping the remainder. Use only where dust does not matter.
  • "up" ceils, inverting a conversion that floored: it gives the smallest unit count worth at least tokenAmount, so toCircuitUnits(toTokenUnits(v, …), …, { round: "up" }) === v where flooring again would lose a unit. With a moving index most unit counts have no exact decimal at the token's decimals, including values a "max" control writes into a field and reads back. Rounding up cannot over-draw: if tokenAmount <= toTokenUnits(balance, …) then the result is <= balance.

Parameters ​

ParameterType
tokenAmountTokenAmount
scalebigint
opts?{ index?: bigint; round?: "exact" | "down" | "up"; }
opts.index?bigint
opts.round?"exact" | "down" | "up"

Returns ​

CircuitAmount

Throws ​

when the amount is not a whole number of circuit units and round is "exact".