bitcore-lib-zcash/docs/uri.md

42 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2015-10-16 09:43:27 -07:00
# Bitcoin URIs
2014-12-19 14:23:48 -08:00
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.
2014-11-28 07:35:53 -08:00
URI Examples:
2015-10-16 09:43:27 -07:00
2014-11-28 07:35:53 -08:00
```
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param
```
2014-12-12 11:26:33 -08:00
## URI Validation
2014-12-15 22:02:05 -08:00
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.
2014-11-28 07:35:53 -08:00
The code for validating URIs looks like this:
2015-10-16 09:43:27 -07:00
2014-11-28 07:35:53 -08:00
```javascript
var uriString = 'bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2';
var valid = URI.isValid(uriString);
var uri = new URI(uriString);
console.log(uri.address.network, uri.amount); // 'livenet', 120000000
```
2014-12-12 11:26:33 -08:00
## URI Parameters
2014-12-19 14:23:48 -08:00
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.
2014-11-28 07:35:53 -08:00
2014-12-15 22:02:05 -08:00
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information.
2014-11-28 07:35:53 -08:00
2014-12-12 11:26:33 -08:00
## Create URI
2014-12-17 12:43:58 -08:00
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.
2014-11-28 07:35:53 -08:00
The code for creating an URI from an Object looks like this:
2015-10-16 09:43:27 -07:00
2014-11-28 07:35:53 -08:00
```javascript
var uriString = new URI({
address: '12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu',
amount : 10000, // in satoshis
message: 'My payment request'
});
var uriString = uri.toString();
```