Class BitcoinURI

java.lang.Object
org.bitcoinj.uri.BitcoinURI

public class BitcoinURI extends Object

Provides a standard implementation of a Bitcoin URI with support for the following:

  • URLEncoded URIs (as passed in by IE on the command line)
  • BIP21 names (including the "req-" prefix handling requirements)

Accepted formats

The following input forms are accepted:

  • bitcoin:<address>
  • bitcoin:<address>?<name1>=<value1>&<name2>=<value2> with multiple additional name/value pairs

The name/value pairs are processed as follows.

  1. URL encoding is stripped and treated as UTF-8
  2. names prefixed with req- are treated as required and if unknown or conflicting cause a parse exception
  3. Unknown names not prefixed with req- are added to a Map, accessible by parameter name
  4. Known names not prefixed with req- are processed unless they are malformed

The following names are known and have the following formats:

  • amount decimal value to 8 dp (e.g. 0.12345678) Note that the exponent notation is not supported any more
  • label any URL encoded alphanumeric
  • message any URL encoded alphanumeric
See Also:
  • Field Details

  • Constructor Details

    • BitcoinURI

      public BitcoinURI(String uri) throws BitcoinURIParseException
      Constructs a new BitcoinURI from the given string. Can be for any network.
      Parameters:
      uri - The raw URI data to be parsed (see class comments for accepted formats)
      Throws:
      BitcoinURIParseException - if the URI is not syntactically or semantically valid.
    • BitcoinURI

      public BitcoinURI(@Nullable NetworkParameters params, String input) throws BitcoinURIParseException
      Constructs a new object by trying to parse the input as a valid Bitcoin URI.
      Parameters:
      params - The network parameters that determine which network the URI is from, or null if you don't have any expectation about what network the URI is for and wish to check yourself.
      input - The raw URI data to be parsed (see class comments for accepted formats)
      Throws:
      BitcoinURIParseException - If the input fails Bitcoin URI syntax and semantic checks.
  • Method Details

    • getAddress

      @Nullable public Address getAddress()
      The Bitcoin address from the URI, if one was present. It's possible to have Bitcoin URI's with no address if a r= payment protocol parameter is specified, though this form is not recommended as older wallets can't understand it.
    • getAmount

      public Coin getAmount()
      Returns:
      The amount name encoded using a pure integer value based at 10,000,000 units is 1 BTC. May be null if no amount is specified
    • getLabel

      public String getLabel()
      Returns:
      The label from the URI.
    • getMessage

      public String getMessage()
      Returns:
      The message from the URI.
    • getPaymentRequestUrl

      public final String getPaymentRequestUrl()
      Returns:
      The URL where a payment request (as specified in BIP 70) may be fetched.
    • getPaymentRequestUrls

      public List<String> getPaymentRequestUrls()
      Returns the URLs where a payment request (as specified in BIP 70) may be fetched. The first URL is the main URL, all subsequent URLs are fallbacks.
    • getParameterByName

      public Object getParameterByName(String name)
      Parameters:
      name - The name of the parameter
      Returns:
      The parameter value, or null if not present
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • convertToBitcoinURI

      public static String convertToBitcoinURI(Address address, Coin amount, String label, String message)
      Simple Bitcoin URI builder using known good fields.
      Parameters:
      address - The Bitcoin address
      amount - The amount
      label - A label
      message - A message
      Returns:
      A String containing the Bitcoin URI
    • convertToBitcoinURI

      public static String convertToBitcoinURI(NetworkParameters params, String address, @Nullable Coin amount, @Nullable String label, @Nullable String message)
      Simple Bitcoin URI builder using known good fields.
      Parameters:
      params - The network parameters that determine which network the URI is for.
      address - The Bitcoin address
      amount - The amount
      label - A label
      message - A message
      Returns:
      A String containing the Bitcoin URI