UNPKG

2.39 kBMarkdownView Raw
1# Networks
2Bitcore 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.
3
4The `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).
5
6## Regtest
7
8The 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:
9
10```javascript
11// Standard testnet
12> bsv.Networks.testnet.networkMagic;
13<Buffer 0b 11 09 07>
14```
15
16```javascript
17// Enabling testnet to use the regtest port and magicNumber
18> bsv.Networks.enableRegtest();
19> bsv.Networks.testnet.networkMagic;
20<Buffer fa bf b5 da>
21```
22
23## Setting the Default Network
24Most 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`).
25
26## Network constants
27The 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.
28
29Take a look at this modified snippet from [networks.js](https://github.com/bitpay/bsv/blob/master/lib/networks.js)
30
31```javascript
32var livenet = new Network();
33_.extend(livenet, {
34 name: 'livenet',
35 alias: 'mainnet',
36 pubkeyhash: 0x00,
37 privatekey: 0x80,
38 scripthash: 0x05,
39 xpubkey: 0x0488b21e,
40 xprivkey: 0x0488ade4,
41 port: 8333
42});
43
44var testnet = new Network();
45_.extend(testnet, {
46 name: 'testnet',
47 alias: 'testnet',
48 pubkeyhash: 0x6f,
49 privatekey: 0xef,
50 scripthash: 0xc4,
51 xpubkey: 0x043587cf,
52 xprivkey: 0x04358394,
53 port: 18333
54});
55```