You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
45 lines
1.6 KiB
10 years ago
|
# URI
|
||
|
|
||
|
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.
|
||
|
|
||
|
URI Examples:
|
||
|
```
|
||
|
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu
|
||
|
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
|
||
|
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param
|
||
|
```
|
||
|
|
||
|
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.
|
||
|
|
||
|
The code for validating uris looks like this:
|
||
|
```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
|
||
|
```
|
||
|
|
||
|
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.
|
||
|
|
||
|
See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki)
|
||
|
for more information.
|
||
|
|
||
|
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.
|
||
|
|
||
|
The code for creating an URI from an Object looks like this:
|
||
|
```javascript
|
||
|
var uriString = new URI({
|
||
|
address: '12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu',
|
||
|
amount : 10000, // in satoshis
|
||
|
message: 'My payment request'
|
||
|
});
|
||
|
var uriString = uri.toString();
|
||
|
```
|