@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 fixedscalenothing 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 leasttokenAmount, sotoCircuitUnits(toTokenUnits(v, …), …, { round: "up" }) === vwhere flooring again would lose a unit. With a moving index most unit counts have no exact decimal at the token'sdecimals, including values a "max" control writes into a field and reads back. Rounding up cannot over-draw: iftokenAmount <= toTokenUnits(balance, …)then the result is<= balance.
Parameters
| Parameter | Type |
|---|---|
tokenAmount | TokenAmount |
scale | bigint |
opts? | { index?: bigint; round?: "exact" | "down" | "up"; } |
opts.index? | bigint |
opts.round? | "exact" | "down" | "up" |
Returns
Throws
when the amount is not a whole number of circuit units and round is "exact".