Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2.05 KB

uri.md

File metadata and controls

63 lines (44 loc) · 2.05 KB

Dash URIs

Represents a Dash payment URI. Dash URI strings is a good standard to share payment request, sometimes as a Dash link or using a QR code.

URI Examples:

dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2
dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2?amount=1.2
dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2?amount=1.2&message=Payment&label=Satoshi&extra=other-param

URI Validation

The main use that we expect you'll have for the URI class in Dashcore is validating and parsing Dash URIs. A URI instance exposes the address as a Dashcore Address object and the amount in satoshis, if present.

The code for validating URIs looks like this:

var uriString = 'dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2?amount=1.2';
var valid = URI.isValid(uriString);
var uri = new URI(uriString);
console.log(uri.address.network, uri.amount); // 'livenet', 120000000

URI Parameters

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 for more information.

Create URI

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.

The code for creating an URI from an Object looks like this:

var uri = new URI({
  address: 'XuUGDZHrKLo841CyamDbG5W7n59epA71h2',
  amount: 10000, // in satoshis
  message: 'My payment request',
});
console.log(uri.toString()); //dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2?amount=0.0001&message=My%20payment%20request

Methods toObject, toJSON and inspect remain available.

fromString

var uri = new URI("dash:XuUGDZHrKLo841CyamDbG5W7n59epA71h2?amount=0.0001&message=My%20payment%20request>")

fromObject

var uri = new URI({
          address:"XuUGDZHrKLo841CyamDbG5W7n59epA71h2",
          amount:"10000",
          message:"My payment request"
          })