For this example you need a running bitcoind instance with RPC enabled.
```js
var bitcore = require('bitcore');
var networks = bitcore.networks;
var Peer = bitcore.Peer;
var PeerManager = require('soop').load('../PeerManager', {
network: networks.testnet
});
var bitcore = require('../bitcore');
var Peer = bitcore.Peer;
var PeerManager = bitcore.PeerManager;
var handleBlock = function(info) {
console.log('** Block Received **');
console.log(info.message);
};
var handleBlock = function(info) {
console.log('** Block Received **');
console.log(info.message);
};
var handleTx = function(info) {
var tx = info.message.tx.getStandardizedObject();
console.log('** TX Received **');
console.log(tx);
};
var handleTx = function(info) {
var tx = info.message.tx.getStandardizedObject();
var handleInv = function(info) {
console.log('** Inv **');
console.log(info.message);
var invs = info.message.invs;
info.conn.sendGetData(invs);
};
console.log('** TX Received **');
console.log(tx);
};
var peerman = new PeerManager();
var handleInv = function(info) {
console.log('** Inv **');
console.log(info.message);
peerman.addPeer(new Peer('127.0.0.1', 18333));
var invs = info.message.invs;
info.conn.sendGetData(invs);
};
peerman.on('connection', function(conn) {
conn.on('inv', handleInv);
conn.on('block', handleBlock);
conn.on('tx', handleTx);
});
var peerman = new PeerManager({
network: 'testnet'
});
peerman.start();
peerman.addPeer(new Peer('127.0.0.1', 18333));
peerman.on('connection', function(conn) {
conn.on('inv', handleInv);
conn.on('block', handleBlock);
conn.on('tx', handleTx);
});
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)
@ -140,83 +141,101 @@ by the transaction size. Documentation on the parameters of `TransactionBuilder`
can be found on the source file.
```js
var bitcore = require('bitcore');
var networks = bitcore.networks;
var Peer = bitcore.Peer;
var TransactionBuilder = bitcore.TransactionBuilder;
var PeerManager = require('soop').load('../PeerManager', {
network: networks.testnet
});
// Unspent transactions can be found via the insight.bitcore.io or blockchain.info APIs