Class: URI

URI

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

Source:
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
json String | Object

JSON string or object of the URI

Source:
Returns:

A new instance of a URI

Type
URI

<static> fromString(str) → {URI}

Instantiate a URI from a String

Parameters:
Name Type Description
str String

JSON string or object of the URI

Source:
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
data string | Object

A bitcoin URI string or an Object

knownParams Array.<string> <optional>

Required non-standard params

Source:
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
uri string

A bitcoin URI string

Source:
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
obj Object

Object with the information

Source:
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
amount String

Amount BTC string

Source:
Throws:

Invalid amount

Type
TypeError
Returns:

Amount represented in satoshis

Type
Object

inspect() → {String}

Will return a string formatted for the console

Source:
Returns:

Bitcoin URI

Type
String

toString() → {String}

Will return a the string representation of the URI

Source:
Returns:

Bitcoin URI string

Type
String