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 withsymbol,decimals, andaddress
Throws
- If
valueis negative or non-numeric - If
valuehas 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 placessymbol(string, optional): Token symbol, defaults to""
Throws
- If
rawis negative
Arithmetic
All arithmetic methods return a newAmount (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()andallowance() - TokenRegistry: Look up TokenInfo for Amount.parse()
