1 | # Bitcoin URIs
|
2 |
|
3 | 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.
|
4 |
|
5 | URI Examples:
|
6 |
|
7 | ```sh
|
8 | bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu
|
9 | bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
|
10 | bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param
|
11 | ```
|
12 |
|
13 | ## URI Validation
|
14 |
|
15 | 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.
|
16 |
|
17 | The code for validating URIs looks like this:
|
18 |
|
19 | ```javascript
|
20 | var uriString = 'bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2';
|
21 | var valid = URI.isValid(uriString);
|
22 | var uri = new URI(uriString);
|
23 | console.log(uri.address.network, uri.amount); // 'livenet', 120000000
|
24 | ```
|
25 |
|
26 | ## URI Parameters
|
27 |
|
28 | 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.
|
29 |
|
30 | See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information.
|
31 |
|
32 | ## Create URI
|
33 |
|
34 | Another important use case for the `URI` class is creating a bitcoin URI for sharing a payment request. That can be accomplished by using a dictionary to create an instance of URI.
|
35 |
|
36 | The code for creating an URI from an Object looks like this:
|
37 |
|
38 | ```javascript
|
39 | var uriString = new URI({
|
40 | address: '12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu',
|
41 | amount : 10000, // in satoshis
|
42 | message: 'My payment request'
|
43 | });
|
44 | var uriString = uri.toString();
|
45 | ```
|