Class: Unit

Unit

new Unit(amount, code) → {Unit}

Bitcore Unit

Utility for handling and converting bitcoins units. The supported units are BTC, mBTC, bits and satoshis. A unit instance can be created with an amount and a unit code, or alternatively using static methods like {fromBTC}. You can consult for different representation of a unit instance using it's {to} method, the fixed unit methods like {toSatoshis} or alternatively using the unit accessors.

Parameters:
Name Type Description
amount Number

The amount to be represented

code String

The unit of the amount

Source:
Returns:

A new instance of an Unit

Type
Unit
Example
var sats = Unit.fromBTC(1.3).toSatoshis();
var mili = Unit.fromBits(1.3).to(Unit.mBTC);
var btc = new Unit(1.3, Unit.bits).BTC;

Members

<static> fromMicros

Will return a Unit instance created from an amount in bits

Source:

toMicros

Will return the value represented in bits

Source:

Methods

<static> fromBTC(amount) → {Unit}

Will return a Unit instance created from an amount in BTC

Parameters:
Name Type Description
amount Number

The amount in BTC

Source:
Returns:

A Unit instance

Type
Unit

<static> fromJSON(json) → {Unit}

Will return a Unit instance created from JSON string or object

Parameters:
Name Type Description
json String | Object

JSON with keys: amount and code

Source:
Returns:

A Unit instance

Type
Unit

<static> fromMilis(amount) → {Unit}

Will return a Unit instance created from an amount in mBTC

Parameters:
Name Type Description
amount Number

The amount in mBTC

Source:
Returns:

A Unit instance

Type
Unit

<static> fromSatoshis(amount) → {Unit}

Will return a Unit instance created from an amount in satoshis

Parameters:
Name Type Description
amount Number

The amount in satoshis

Source:
Returns:

A Unit instance

Type
Unit

inspect() → {String}

Will return a string formatted for the console

Source:
Returns:

the value in satoshis

Type
String

to(code) → {Number}

Will return the value represented in the specified unit

Parameters:
Name Type Description
code string

The unit code

Source:
Returns:

The converted value

Type
Number

toBTC() → {Number}

Will return the value represented in BTC

Source:
Returns:

The value converted to BTC

Type
Number

toMilis() → {Number}

Will return the value represented in mBTC

Source:
Returns:

The value converted to mBTC

Type
Number

toObject() → {Object}

Will return a plain object representation of the Unit

Source:
Returns:

An object with the keys: amount and code

Type
Object

toSatoshis() → {Number}

Will return the value represented in satoshis

Source:
Returns:

The value converted to satoshis

Type
Number

toString() → {String}

Will return a the string representation of the value in satoshis

Source:
Returns:

the value in satoshis

Type
String