@chipi-stack/core is in development (v0.1.0). APIs may change before stable release.
Overview
Amount is an immutable value type that represents a token amount using BigInt internally. All arithmetic is exact with zero floating-point precision loss.
Usage
Factory Methods
Amount.parse(value, token)
Parse a human-readable string into an Amount.
Parameters
value (string): Human-readable value (e.g., "1.5", "100")
token (TokenInfo): Object with symbol, decimals, and address
Throws
- If
value is negative or non-numeric
- If
value has more decimal places than the token supports
Amount.fromRaw(raw, decimals, symbol?)
Create an Amount from a raw bigint value (base units).
Parameters
raw (bigint): Raw value in base units (e.g., wei)
decimals (number): Token decimal places
symbol (string, optional): Token symbol, defaults to ""
Throws
Arithmetic
All arithmetic methods return a new Amount (immutable). Both operands must have the same decimals.
Methods
Comparisons
Methods
Formatting
Methods
Properties
Example
Related
- TxBuilder: Use Amount with TxBuilder for typed transfers
- Erc20: Returns Amount objects from
balanceOf() and allowance()
- TokenRegistry: Look up TokenInfo for Amount.parse()