Enum Class BitcoinNetwork

java.lang.Object
java.lang.Enum<BitcoinNetwork>
org.bitcoinj.base.BitcoinNetwork
All Implemented Interfaces:
Serializable, Comparable<BitcoinNetwork>, Constable, Network

public enum BitcoinNetwork extends Enum<BitcoinNetwork> implements Network
A convenient enum representation of a Bitcoin network.

Note that the name of each enum constant is defined in uppercase as is the convention in Java. However, the canonical representation in bitcoinj for user-facing display and input of Bitcoin network names is lowercase (e.g. as a command-line parameter.) Implementations should use the toString() method for output and the fromString(String) method for input of network values.

  • Enum Constant Details

    • MAINNET

      public static final BitcoinNetwork MAINNET
      The main Bitcoin network, known as "mainnet", with id string "org.bitcoin.production"
    • TESTNET

      public static final BitcoinNetwork TESTNET
      The Bitcoin test network, known as "testnet", with id string "org.bitcoin.test"
    • SIGNET

      public static final BitcoinNetwork SIGNET
      The Bitcoin signature-based test network, known as "signet", with id string "org.bitcoin.signet"
    • REGTEST

      public static final BitcoinNetwork REGTEST
      A local Bitcoin regression test network, known as "regtest", with id string "org.bitcoin.regtest"
  • Field Details

    • BITCOIN_SCHEME

      public static final String BITCOIN_SCHEME
      Scheme part for Bitcoin URIs.
      See Also:
    • MAX_MONEY

      public static final Coin MAX_MONEY
      The maximum money to be generated
    • ID_MAINNET

      public static final String ID_MAINNET
      The ID string for the main, production network where people trade things.
    • ID_TESTNET

      public static final String ID_TESTNET
      The ID string for the testnet.
    • ID_SIGNET

      public static final String ID_SIGNET
      The ID string for the signet.
    • ID_REGTEST

      public static final String ID_REGTEST
      The ID string for regtest mode.
  • Method Details

    • values

      public static BitcoinNetwork[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BitcoinNetwork valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • toString

      public String toString()
      Return the canonical, lowercase, user-facing String for an enum. It is the lowercase value of Enum.name() and can be displayed to the user, used as a command-line parameter, etc.
      MAINNET
      mainnet
      TESTNET
      testnet
      SIGNET
      signet
      REGTEST
      regtest
      Overrides:
      toString in class Enum<BitcoinNetwork>
      Returns:
      canonical lowercase name for this Bitcoin network
    • id

      public String id()
      Return the network ID string as defined by (these were previously defined in NetworkParameters)
      MAINNET
      org.bitcoin.production
      TESTNET
      org.bitcoin.test
      SIGNET
      org.bitcoin.signet
      REGTEST
      org.bitcoin.regtest
      Specified by:
      id in interface Network
      Returns:
      The network ID string
    • legacyAddressHeader

      public int legacyAddressHeader()
      Header byte of base58 encoded legacy P2PKH addresses for this network.
      Specified by:
      legacyAddressHeader in interface Network
      Returns:
      header byte as an int.
      See Also:
    • legacyP2SHHeader

      public int legacyP2SHHeader()
      Header byte of base58 encoded legacy P2SH addresses for this network.
      Specified by:
      legacyP2SHHeader in interface Network
      Returns:
      header byte as an int.
      See Also:
    • segwitAddressHrp

      public String segwitAddressHrp()
      Return the standard Bech32 SegwitAddress.SegwitHrp (as a String) for this network.
      Specified by:
      segwitAddressHrp in interface Network
      Returns:
      The HRP as a (lowercase) string.
    • uriScheme

      public String uriScheme()
      The URI scheme for Bitcoin.
      Specified by:
      uriScheme in interface Network
      Returns:
      string containing the URI scheme
      See Also:
    • hasMaxMoney

      public boolean hasMaxMoney()
      Description copied from interface: Network
      Does this network have a fixed maximum number of coins
      Specified by:
      hasMaxMoney in interface Network
      Returns:
      true if this network has a fixed maximum number of coins
    • maxMoney

      public Coin maxMoney()
      Description copied from interface: Network
      Maximum number of coins for this network as a Monetary value. Where not applicable, a very large number of coins is returned instead (e.g. the main coin issue for Dogecoin).
      Specified by:
      maxMoney in interface Network
      Returns:
      Maximum number of coins for this network
    • exceedsMaxMoney

      public boolean exceedsMaxMoney(Monetary amount)
      Description copied from interface: Network
      Check if an amount exceeds the maximum allowed for a network (if the network has one)
      Specified by:
      exceedsMaxMoney in interface Network
      Parameters:
      amount - A monetary amount
      Returns:
      true if too big, false if an allowed amount
    • checkAddress

      public Address checkAddress(Address address) throws IllegalArgumentException
      Check if an address is valid on this network. This is meant to be used as a precondition for a method or function that expects a valid address. If you are validating addresses provided externally, you probably want to use isValidAddress(Address) to handle errors more gracefully. This method uses isValidAddress(Address) internally which properly accounts for address normalization.
      Parameters:
      address - Address to validate
      Returns:
      The unmodified address if valid on this network
      Throws:
      IllegalArgumentException - if address not valid on this network
    • isValidAddress

      public boolean isValidAddress(Address address)
      Is address valid for this network. Because we normalize the network() value in the Address type (see the JavaDoc for Address.network()) this method should be used in preference to simply verifying that address.network() returns the desired network type.
      Parameters:
      address - Address to validate
      Returns:
      true if valid on this network, false otherwise
    • fromString

      public static Optional<BitcoinNetwork> fromString(String nameString)
      Find the BitcoinNetwork from a name string, e.g. "mainnet", "testnet" or "signet". A number of common alternate names are allowed too, e.g. "main" or "prod".
      Parameters:
      nameString - A name string
      Returns:
      An Optional containing the matching enum or empty
    • fromIdString

      public static Optional<BitcoinNetwork> fromIdString(String idString)
      Find the BitcoinNetwork from an ID String
      Parameters:
      idString - specifies the network
      Returns:
      An Optional containing the matching enum or empty
    • strings

      public static List<String> strings()
      Returns:
      list of the names of all instances of this enum