Represents a bitcoin payment uri. Bitcoin URI strings became the most popular
Represents a bitcoin payment uri. Bitcoin URI strings became the most popular way to share payment request, sometimes as a bitcoin link and others using a QR code.
way to share payment request, sometimes as a bitcoin link and others using a QR code.
The main use that we expect you'll have for the `URI` class in bitcore is
The main use that we expect you'll have for the `URI` class in bitcore is validating and parsing bitcoin URIs. A `URI` instance exposes the address as a bitcore `Address` object and the amount in Satoshis, if present.
validating and parsing bitcoin URIs. A `URI` instance exposes the address as a
bitcore `Address` object and the amount in Satoshis, if present.
All standard parameters can be found as members of the `URI` instance. However
All standard parameters can be found as members of the `URI` instance. However a bitcoin uri may contain other non-standard parameters, all those can be found under the `extra` namespace.
a bitcoin uri may contain other non-standard parameters, all those can be found
under the `extra` namespace.
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki)
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information.
for more information.
Other usecase important usecase for the `URI` class is creating a bitcoin URI for
Other usecase important usecase for the `URI` class is creating a bitcoin URI for sharing a payment request. That can be acomplished by using an Object to create an instance of URI.
sharing a payment request. That can be acomplished by using an Object to create
an instance of URI.
The code for creating an URI from an Object looks like this:
The code for creating an URI from an Object looks like this:
Unit it's a utility for handling and converting bitcoins units. We strongly
Unit is an utility for handling and converting bitcoins units. We strongly recommend you to always use satoshis to represent amount inside your application and only convert them to other units in the front-end.
recommend you to always use satoshis to represent amount inside your application
and only convert them to other units in the front-end.
The supported units are BTC, mBTC, bits and satoshis. The codes for each unit
The supported units are BTC, mBTC, bits and satoshis. The codes for each unit can be found as members of the Unit class.
can be found as members of the Unit class.
```javascript
```javascript
var btcCode = Unit.BTC;
var btcCode = Unit.BTC;
var mbtcCode = Unit.mBTC;
var mbtcCode = Unit.mBTC;
var ubtcCode = Unit.uBTC;
var bitsCode = Unit.bits;
var bitsCode = Unit.bits;
var satsCode = Unit.satoshis;
var satsCode = Unit.satoshis;
```
```
There are two ways for creating a unit instance. You can instanciate the class
There are two ways for creating a unit instance. You can instanciate the class using a value and a unit code; alternatively if the unit it's fixed you could you some of the static methods. Check some examples below:
using a value and a unit code; alternatively if the unit it's fixed you could
you some of the static methods. Check some examples below:
```javascript
```javascript
var unit;
var unit;
@ -33,10 +29,7 @@ unit = Unit.fromBits(amount);
unit = Unit.fromSatoshis(amount);
unit = Unit.fromSatoshis(amount);
```
```
Once you have a unit instance, you can check it's representantion in all the
Once you have a unit instance, you can check it's representantion in all the available units. For your convinience the classes expose three ways to acomplish this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()` or by using the accessors.
available units. For your convinience the classes expose three ways to acomplish
this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()`