Networks

Bitcore provides support for the main bitcoin network as well as for testnet3, the current test blockchain. We encourage the use of Networks.livenet and Networks.testnet as constants. Note that the library sometimes may check for equality against this object. Please avoid creating a deep copy of this object.

The Network namespace has a function, get(...) that returns an instance of a Network or undefined. The only argument to this function is some kind of identifier of the network: either its name, a reference to a Network object, or a number used as a magic constant to identify the network (for example, the value 0 that gives bitcoin addresses the distinctive '1' at its beginning on livenet, is a 0x6F for testnet).

Regtest

The regtest network is useful for development as it's possible to programmatically and instantly generate blocks for testing. It's currently supported as a variation of testnet. Here is an example of how to use regtest with the Bitcore Library:

// Standard testnet
> bitcore.Networks.testnet.networkMagic;
<Buffer 0b 11 09 07>
// Enabling testnet to use the regtest port and magicNumber
> bitcore.Networks.enableRegtest();
> bitcore.Networks.testnet.networkMagic;
<Buffer fa bf b5 da>

Setting the Default Network

Most projects will only need to work with one of the networks. The value of Networks.defaultNetwork can be set to Networks.testnet if the project will need to only to work on testnet (the default is Networks.livenet).

Network constants

The functionality of testnet and livenet is mostly similar (except for some relaxed block validation rules on testnet). They differ in the constants being used for human representation of base58 encoded strings. These are sometimes referred to as "version" constants.

Take a look at this modified snippet from networks.js

var livenet = new Network();
_.extend(livenet, {
  name: 'livenet',
  alias: 'mainnet',
  pubkeyhash: 0x00,
  privatekey: 0x80,
  scripthash: 0x05,
  xpubkey:  0x0488b21e,
  xprivkey: 0x0488ade4,
  port: 8333
});

var testnet = new Network();
_.extend(testnet, {
  name: 'testnet',
  alias: 'testnet',
  pubkeyhash: 0x6f,
  privatekey: 0xef,
  scripthash: 0xc4,
  xpubkey: 0x043587cf,
  xprivkey: 0x04358394,
  port: 18333
});

Classes

Network

Objects

Networks : object

Network

Kind: global class

new Network()

A network is merely a map containing values that correspond to version numbers for each bitcoin network. Currently only supporting "livenet" (a.k.a. "mainnet") and "testnet".

Networks : object

Kind: global namespace

networks.get ⇒

Kind: instance property of Networks
Returns: Network

Param Type Description
arg string | number | Network
keys string | Array if set, only check if the magic number associated with this name matches

networks.add ⇒

Kind: instance property of Networks
Returns: Network

Param Type Description
data Object
data.name string The name of the network
data.alias string The aliased name of the network
data.pubkeyhash Number The publickey hash prefix
data.privatekey Number The privatekey prefix
data.scripthash Number The scripthash prefix
data.xpubkey Number The extended public key magic
data.xprivkey Number The extended private key magic
data.networkMagic Number The network magic number
data.port Number The network port
data.dnsSeeds Array An array of dns seeds

networks.remove

Kind: instance property of Networks

Param Type
network Network

networks.livenet

Kind: instance property of Networks

networks.testnet

Kind: instance property of Networks

networks.enableRegtest

Kind: instance property of Networks

networks.disableRegtest

Kind: instance property of Networks