UNPKG

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