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)
## Creating and sending a Transaction through P2P
```
```js
var networks = require('bitcore/networks');
var Peer = require('bitcore/Peer').class();
var Transaction = require('bitcore/Transaction').class();
@ -91,23 +117,29 @@ var PeerManager = require('bitcore/PeerManager').createClass({
});
var createTx = function() {
var TXIN = 'd05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265';
var TXIN_N = 0;
var ADDR = 'muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz';
var VAL = '1.234';
var txobj = {};
txobj.version = 1;
txobj.lock_time = 0;
txobj.ins = [];
txobj.outs = [];
var txin = {};
txin.s = coinUtil.EMPTY_BUFFER; //Add signature
txin.q = 0xffffffff;
var hash = new Buffer(TXIN, 'hex');
hash.reverse();
var txobj = {
version: 1,
lock_time: 0,
ins: [],
outs: []
}
var txin = {
s: coinUtil.EMPTY_BUFFER, // Add signature
q: 0xffffffff
};
var hash = new Buffer(TXIN.split('').reverse(), 'hex');
var vout = parseInt(TXIN_N);
var voutBuf = new Buffer(4);
voutBuf.writeUInt32LE(vout, 0);
txin.o = Buffer.concat([hash, voutBuf]);
txobj.ins.push(txin);
@ -124,22 +156,35 @@ var createTx = function() {
txobj.outs.push(txout);
return new Transaction(txobj);
};
var peerman = new PeerManager();
peerman.addPeer(new Peer('127.0.0.1', 18333));
peerman.on('connect', function(conn) {
var conn = peerman.getActiveConnection();
if (conn)
if (conn) {
conn.sendTx(createTx());
conn.on('reject', function () { console.log('Transaction Rejected'); } );
}
conn.on('reject', function () {
console.log('Transaction Rejected');
});
});
peerman.start();
```
## Consuming bitcoind RPC
```
var RpcClient = require('../RpcClient').class();
```js
var util = require('util');
var RpcClient = require('bitcore/RpcClient').class();
var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';