For this example you need a running bitcoind instance with RPC enabled.
For this example you need a running bitcoind instance with RPC enabled.
```js
```js
var util = require('util');
var bitcore = require('bitcore');
var networks = require('bitcore/networks');
var networks = bitcore.networks;
var Peer = require('bitcore/Peer');
var Peer = bitcore.Peer;
var PeerManager = require('soop').load('bitcore/PeerManager',
var PeerManager = require('soop').load('../PeerManager', {
{network: networks.testnet});
network: networks.testnet
});
var handleBlock = function(info) {
var handleBlock = function(info) {
console.log('** Block Received **');
console.log('** Block Received **');
console.log(info.message);
console.log(info.message);
};
};
var handleTx = function(info) {
var handleTx = function(info) {
var tx = info.message.tx.getStandardizedObject();
var tx = info.message.tx.getStandardizedObject();
console.log('** Block TX **');
console.log('** TX Received**');
console.log(tx);
console.log(tx);
};
};
var handleInv = function(info) {
var handleInv = function(info) {
console.log('** Inv **');
console.log('** Block Inv **');
console.log(info.message);
console.log(info.message);
var invs = info.message.invs;
var invs = info.message.invs;
info.conn.sendGetData(invs);
info.conn.sendGetData(invs);
};
};
var peerman = new PeerManager();
var peerman = new PeerManager();
peerman.addPeer(new Peer('127.0.0.1', 18333));
peerman.addPeer(new Peer('127.0.0.1', 18333));
peerman.on('connection', function(conn) {
peerman.on('connection', function(conn) {
conn.on('inv', handleInv);
conn.on('inv', handleInv);
conn.on('block', handleBlock);
conn.on('block', handleBlock);
conn.on('tx', handleTx);
conn.on('tx', handleTx);
});
});
peerman.start();
peerman.start();
```
```
PeerManager will emit the following events: 'version', 'verack', 'addr', 'getaddr', 'error' 'disconnect'; and will relay events like: 'tx', 'block', 'inv'. Please see [PeerManager.js](PeerManager.js), [Peer.js](Peer.js) and [Connection.js](Connection.js)
PeerManager will emit the following events: 'version', 'verack', 'addr', 'getaddr', 'error' 'disconnect'; and will relay events like: 'tx', 'block', 'inv'. Please see [PeerManager.js](PeerManager.js), [Peer.js](Peer.js) and [Connection.js](Connection.js)
## Consuming bitcoind RPC
For this example you need a running bitcoind instance with RPC enabled.
```js
var bitcore = require('bitcore');
var RpcClient = bitcore.RpcClient;
var hash = '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';