new URI(data, knownParams) → {URI}
Bitcore URI
Instantiate an URI from a bitcoin URI String or an Object. An URI instance can be created with a bitcoin uri string or an object. All instances of URI are valid, the static method isValid allows checking before instanciation.
All standard parameters can be found as members of the class, the address is represented using an {Address} instance and the amount is represented in satoshis. Any other non-standard parameters can be found under the extra member.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
data |
string | Object | A bitcoin URI string or an Object |
|
knownParams |
Array.<string> |
<optional> |
Required non-standard params |
Throws:
-
-
Invalid bitcoin address
- Type
- TypeError
-
-
-
Invalid amount
- Type
- TypeError
-
-
-
Unknown required argument
- Type
- Error
-
Returns:
A new valid and frozen instance of URI
- Type
- URI
Example
var uri = new URI('bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2');
console.log(uri.address, uri.amount);
Methods
-
<static> fromJSON(json) → {URI}
-
Instantiate a URI from JSON
Parameters:
Name Type Description jsonString | Object JSON string or object of the URI
Returns:
A new instance of a URI
- Type
- URI
-
<static> fromString(str) → {URI}
-
Instantiate a URI from a String
Parameters:
Name Type Description strString JSON string or object of the URI
Returns:
A new instance of a URI
- Type
- URI
-
<static> isValid(data, knownParams) → {boolean}
-
Check if an bitcoin URI string is valid
Parameters:
Name Type Argument Description datastring | Object A bitcoin URI string or an Object
knownParamsArray.<string> <optional>
Required non-standard params
Returns:
Result of uri validation
- Type
- boolean
Example
var valid = URI.isValid('bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu'); // true -
<static> parse(uri) → {Object}
-
Convert a bitcoin URI string into a simple object.
Parameters:
Name Type Description uristring A bitcoin URI string
Throws:
-
Invalid bitcoin URI
- Type
- TypeError
Returns:
An object with the parsed params
- Type
- Object
-
-
_fromObject(obj)
-
Internal function to load the URI instance with an object.
Parameters:
Name Type Description objObject Object with the information
Throws:
-
-
Invalid bitcoin address
- Type
- TypeError
-
-
-
Invalid amount
- Type
- TypeError
-
-
-
Unknown required argument
- Type
- Error
-
-
-
_parseAmount(amount) → {Object}
-
Internal function to transform a BTC string amount into satoshis
Parameters:
Name Type Description amountString Amount BTC string
Throws:
-
Invalid amount
- Type
- TypeError
Returns:
Amount represented in satoshis
- Type
- Object
-
-
inspect() → {String}
-
Will return a string formatted for the console
Returns:
Bitcoin URI
- Type
- String
-
toString() → {String}
-
Will return a the string representation of the URI
Returns:
Bitcoin URI string
- Type
- String