Class: Amount

btc.Amount

new Amount(valuenullable, unitnullable, numnullable)

Represents a bitcoin amount (satoshis internally).

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
num Boolean <nullable>
Properties:
Name Type Description
value Amount
Source:

Methods

(static) btc(value) → {String}

Safely convert satoshis to a BTC string. This function explicitly avoids any floating point arithmetic.

Parameters:
Name Type Description
value Amount

Satoshis.

Source:
Returns:

BTC string.

Type
String

(static) from(unit, value, numnullable) → {Amount}

Instantiate amount from unit.

Parameters:
Name Type Attributes Description
unit String
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(static) fromBits(value, numnullable) → {Amount}

Instantiate amount from bits.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(static) fromBTC(value, numnullable) → {Amount}

Instantiate amount from btc.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(static) fromMBTC(value, numnullable) → {Amount}

Instantiate amount from mbtc.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(static) fromOptions(valuenullable, unitnullable, numnullable) → {Amount}

Instantiate amount from options.

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
num Boolean <nullable>
Source:
Returns:
Type
Amount

(static) fromSatoshis(value, numnullable) → {Amount}

Instantiate amount from satoshis.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private, static) fromValue(value) → {Amount}

Instantiate amount from value.

Parameters:
Name Type Description
value Amount
Source:
Returns:
Type
Amount

(static) parse(value, exp, num) → {Amount}

Safely convert a BTC string to satoshis. This function explicitly avoids any floating point arithmetic. It also does extra validation to ensure the resulting Number will be 53 bits or less.

Parameters:
Name Type Description
value String

BTC

exp Number

Exponent.

num Boolean

Allow numbers.

Source:
Throws:

on parse error

Returns:

Satoshis.

Type
Amount

(static) parseUnsafe(value, exp, num) → {Amount}

Unsafely convert a BTC string to satoshis.

Parameters:
Name Type Description
value String

BTC

exp Number

Exponent.

num Boolean

Allow numbers.

Source:
Throws:

on parse error

Returns:

Satoshis.

Type
Amount

(static) serialize(value, exp, num) → {String}

Safely convert satoshis to a BTC string. This function explicitly avoids any floating point arithmetic.

Parameters:
Name Type Description
value Amount
exp Number

Exponent.

num Boolean

Return a number.

Source:
Returns:
Type
String

(static) serializeUnsafe(value, exp, num) → {String}

Unsafely convert satoshis to a BTC string.

Parameters:
Name Type Description
value Amount
exp Number

Exponent.

num Boolean

Return a number.

Source:
Returns:
Type
String

(static) value(value) → {Amount}

Safely convert a BTC string to satoshis.

Parameters:
Name Type Description
value String

BTC

Source:
Throws:

on parse error

Returns:

Satoshis.

Type
Amount

(private) from(unit, value, numnullable) → {Amount}

Inject properties from unit.

Parameters:
Name Type Attributes Description
unit String
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private) fromBits(value, numnullable) → {Amount}

Inject properties from bits.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private) fromBTC(value, numnullable) → {Amount}

Inject properties from btc.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private) fromMBTC(value, numnullable) → {Amount}

Inject properties from mbtc.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private) fromOptions(valuenullable, unitnullable, numnullable) → {Amount}

Inject properties from options.

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
num Boolean <nullable>
Source:
Returns:
Type
Amount

(private) fromSatoshis(value, numnullable) → {Amount}

Inject properties from satoshis.

Parameters:
Name Type Attributes Description
value Number | String
num Bolean <nullable>
Source:
Returns:
Type
Amount

(private) fromValue(value) → {Amount}

Inject properties from value.

Parameters:
Name Type Description
value Amount
Source:
Returns:
Type
Amount

inspect() → {String}

Inspect amount.

Source:
Returns:
Type
String

to(unit, numnullable) → {String|Amount}

Get unit string or value.

Parameters:
Name Type Attributes Description
unit String

Can be sat, ubtc, bits, mbtc, or btc.

num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toBits(numnullable) → {String|Amount}

Get bits string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toBTC(numnullable) → {String|Amount}

Get btc string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toMBTC(numnullable) → {String|Amount}

Get mbtc string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toSatoshis(numnullable) → {String|Amount}

Get satoshi string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toString() → {String}

Convert amount to bitcoin string.

Source:
Returns:
Type
String

toValue() → {Amount}

Get satoshi value.

Source:
Returns:
Type
Amount