Skip to content

parseUnits

parseUnits(value, decimals): bigint

Defined in: utils/parse-units.ts:30

Parse a decimal string into the smallest unit (e.g. wei) as a bigint, given the number of decimal places.

Similar to “parseUnits” in ethers.js

Similar to “parseUnits” in viem

Parameters

value

string

the decimal string to parse

decimals

number = 18

the number of decimal places (default 18)

Returns

bigint

a bigint in the smallest unit

Examples

parseUnits('1', 6)
// 1000000n
parseUnits('1.5', 6)
// 1500000n
parseUnits('1', 18)
// 1000000000000000000n