Amount

class Amount(value, unit, newUnit)

exported from models/amount

A wrapper around amounts with units. Over the network, amounts are sent as raw bytes. In the client, they are exposed as BigInts, but also compatible with plain strings or numbers (if smaller than 2^31-1) Uses ‘aergo’ as default unit when passing strings or numbers. Uses ‘aer’ as default unit when passing BigInts, buffers or byte arrays. Whenever you pass amounts to other functions, they will try to coerce them using this class.

Arguments:
  • value (models/amount.Amount|JSBI|number|string|Buffer|Uint8Array) –
  • unit (string) –
  • newUnit (string) –
Amount.unit

type: string

Amount.value

type: JSBI

Amount._valueFromString(value, unit)
Arguments:
  • value (string) –
  • unit (string) –
Returns:

JSBI

Amount.add(otherAmount)
Arguments:
  • otherAmount (models/amount.Amount|number|JSBI) –
Returns:

models/amount.Amount

Amount.asBytes()

Returns value as byte buffer

Returns:Buffer
Amount.compare(otherAmount)
Arguments:
  • otherAmount (models/amount.Amount|number|JSBI) –
Returns:

number

Amount.equal(otherAmount)
Arguments:
  • otherAmount (models/amount.Amount|number|JSBI) –
Returns:

boolean

Amount.formatNumber(unit)
Arguments:
  • unit (string) –
Returns:

string

Amount.moveDecimalPoint(str, digits)

Move decimal point in string by digits, positive to the right, negative to the left. This extends the string if necessary. Example: (“0.0001”, 4 => “1”), (“0.0001”, -4 => “0.00000001”)

Arguments:
  • str (string) –
  • digits (number) –
Returns:

string

Amount.sub(otherAmount)
Arguments:
  • otherAmount (models/amount.Amount|number|JSBI) –
Returns:

models/amount.Amount

Amount.toJSON()
Returns:string
Amount.toString()

Returns formatted string including unit

Returns:string
Amount.toUnit(unit)

Convert to another unit

Arguments:
  • unit (string) – string (aer, gaer, aergo)
Returns:

models/amount.Amount