bitcore-lib-zcash/docs/networks.md

47 lines
1.9 KiB
Markdown
Raw Normal View History

---
2014-12-23 07:28:31 -08:00
title: Networks
description: A simple interface to handle livenet and testnet bitcoin networks.
---
2014-12-19 14:23:48 -08:00
# Networks
2014-12-12 11:26:33 -08:00
## Description
2014-11-24 06:08:02 -08:00
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.
2014-12-15 21:59:02 -08:00
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).
2014-11-24 06:08:02 -08:00
2014-12-19 14:23:48 -08:00
## Setting the Default Network
2014-11-24 06:08:02 -08:00
2014-12-19 14:23:48 -08:00
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`).
2014-11-24 06:08:02 -08:00
## Network constants
2014-12-15 21:59:02 -08:00
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.
2014-12-17 11:06:44 -08:00
Take a look at this modified snippet from [networks.js](https://github.com/bitpay/bitcore/blob/master/lib/networks.js)
2014-12-15 21:59:02 -08:00
```javascript
var livenet = new Network();
_.extend(livenet, {
name: 'livenet',
alias: 'mainnet',
pubkeyhash: 0x00,
privatekey: 0x80,
scripthash: 0x05,
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4,
port: 8333
});
2014-11-24 06:08:02 -08:00
2014-12-15 21:59:02 -08:00
var testnet = new Network();
_.extend(testnet, {
name: 'testnet',
alias: 'testnet',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
port: 18333
});
```