https://github.com/bitpay/chainlib-bitcoin
A Bitcoin blockchain library for Node.js
https://github.com/bitpay/chainlib-bitcoin
Last synced: about 1 year ago
JSON representation
A Bitcoin blockchain library for Node.js
- Host: GitHub
- URL: https://github.com/bitpay/chainlib-bitcoin
- Owner: bitpay
- License: mit
- Created: 2015-06-02T17:18:03.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-20T21:58:16.000Z (almost 11 years ago)
- Last Synced: 2025-04-06T08:03:03.288Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1010 KB
- Stars: 6
- Watchers: 15
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ChainLib Bitcoin
=======
[](https://travis-ci.org/bitpay/chainlib-bitcoin)
[](https://coveralls.io/r/bitpay/chainlib-bitcoin)
A library for building Bitcoin chain based databases.
**Chainlib-bitcoin is not actively maintained anymore. Please check out [bitcoind.js](https://github.com/bitpay/bitcoind.js), which is similar, but runs bitcoind in the same node process and uses it to query blocks, transactions, unspent outputs and the mempool.**
## Getting Started
### Install
```bash
git clone git@github.com:bitpay/chainlib-bitcoin.git
cd chainlib-bitcoin
npm install
```
### Example Usage
```js
var BitcoinNode = require('chainlib-bitcoin').RPCNode;
var privkey = 'tprv8ZgxMBicQKsPdj1QowoT9z1tY5Et38qaMjCHZVoPdPFb6narfmYkqTygEVHfUmY78k3HcaEpkyNCAQDANaXtwNe1HLFvcA7nqYj1B7wTSTo';
var configuration = {
db: {
xprivkey: privkey,
path: './bitcoin-testnet.db'
},
p2p: {
addrs: [
{
ip: {
v4: '127.0.0.1'
},
port: 18333
}
],
dnsSeed: false
},
rpc: {
host: 'localhost',
port: 18332,
user: 'user',
pass: 'password',
ssl: false,
sslStrict: false
},
testnet: true
};
var node = new BitcoinNode(configuration);
node.chain.on('addblock', function(block) {
console.log('New Best Tip:', block.hash);
});
```
### API Documentation
Get Unspent Outputs
```js
var address = '15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2';
var includeMempool = true;
node.getUnspentOutputs(address, includeMempool, function(err, unspentOutputs) {
//...
});
```
View Balances
```js
var address = '15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2';
var includeMempool = true;
node.getBalance(address, includeMempool, function(err, balance) {
//...
});
```
Get Outputs
```js
var address = '15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2';
var includeMempool = true;
node.getOutputs(address, includeMempool, function(err, outputs) {
//...
});
```
Get Transaction
```js
var txid = 'c349b124b820fe6e32136c30e99f6c4f115fce4d750838edf0c46d3cb4d7281e';
var includeMempool = true;
node.getTransaction(txid, includeMempool, function(err, transaction) {
//...
});
```
Get Block
```js
var blockHash = '00000000d17332a156a807b25bc5a2e041d2c730628ceb77e75841056082a2c2';
node.getBlock(blockHash, function(err, block) {
//...
});
```
### Tests and Coverage
To run all of the tests:
```bash
npm run test
npm run coverage
```
To run a single test file in watch mode (useful for developing):
```bash
mocha -w -R spec test/db.unit.js
```