The Bitcoin Service is a Node.js interface to [Bitcoin Core](https://github.com/bitcoin/bitcoin) for querying information about the bitcoin block chain. It will manage starting and stopping `bitcoind` or connect to several running `bitcoind` processes. It uses a branch of a [branch of Bitcoin Core](https://github.com/bitpay/bitcoin/tree/0.12.1-bitcore) with additional indexes for querying information about addresses and blocks. Results are cached for performance and there are several additional API methods added for common queries.
The default configuration will include a "spawn" configuration in "bitcoind". This defines the location of the block chain database and the location of the `bitcoind` daemon executable. The below configuration points to a local clone of `bitcoin`, and will start `bitcoind` automatically with your Node.js application.
```json
"servicesConfig": {
"bitcoind": {
"spawn": {
"datadir": "/home/bitcore/.bitcoin",
"exec": "/home/bitcore/bitcoin/src/bitcoind"
}
}
}
```
It's also possible to connect to separately managed `bitcoind` processes with round-robin quering, for example:
```json
"servicesConfig": {
"bitcoind": {
"connect": [
{
"rpchost": "127.0.0.1",
"rpcport": 30521,
"rpcuser": "bitcoin",
"rpcpassword": "local321",
"zmqpubrawtx": "tcp://127.0.0.1:30611"
},
{
"rpchost": "127.0.0.1",
"rpcport": 30522,
"rpcuser": "bitcoin",
"rpcpassword": "local321",
"zmqpubrawtx": "tcp://127.0.0.1:30622"
},
{
"rpchost": "127.0.0.1",
"rpcport": 30523,
"rpcuser": "bitcoin",
"rpcpassword": "local321",
"zmqpubrawtx": "tcp://127.0.0.1:30633"
}
]
}
}
```
**Note**: For detailed example configuration see [`regtest/cluster.js`](regtest/cluster.js)
One of the most common uses will be to retrieve unspent outputs necessary to create a transaction, here is how to get the unspent outputs for an address:
```js
var address = 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW';
// balance will be in satoshis with "received" and "balance"
});
```
**View Address History**
This method will give history of an address limited by a range of block heights by using the "start" and "end" arguments. The "start" value is the more recent, and greater, block height. The "end" value is the older, and lesser, block height. This feature is most useful for synchronization as previous history can be omitted. Furthermore for large ranges of block heights, results can be paginated by using the "from" and "to" arguments.
```js
var addresses = ['mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW'];
-`totalReceived` does not exclude change *(the amount of satoshis originating from the same address)*
-`unconfirmedBalance` is the delta that the unconfirmed transactions have on the total balance *(can be both positive and negative)*
-`unconfirmedAppearances` is the total number of unconfirmed transactions
-`appearances` is the total confirmed transactions
-`txids` Are sorted in block order with the most recent at the beginning. A maximum of 1000 *(default)* will be returned, the `from` and `to` options can be used to get further values.