example usage missing require, priv key creation
a few changes that i needed to make to the example to make it run for me
This commit is contained in:
parent
4e7dbae829
commit
b94b15aba6
25
README.md
25
README.md
@ -13,11 +13,20 @@ compiling a binding to an ECDSA library is not even required for node.js).
|
|||||||
satoshi protocol, which will also optionally give the user the ability download
|
satoshi protocol, which will also optionally give the user the ability download
|
||||||
the entire blockchain.
|
the entire blockchain.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install bcoin
|
||||||
|
$ npm install levelup
|
||||||
|
$ npm install leveldown
|
||||||
|
```
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
``` js
|
``` js
|
||||||
var bcoin = require('bcoin');
|
var bcoin = require('bcoin');
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
// Standard bitcoin seeds
|
// Standard bitcoin seeds
|
||||||
var seeds = [
|
var seeds = [
|
||||||
@ -86,14 +95,26 @@ pool.on('block', function(block, peer) {
|
|||||||
pool.on('tx', function(tx, peer) {
|
pool.on('tx', function(tx, peer) {
|
||||||
var hash = bcoin.utils.revHex(tx.hash('hex'));
|
var hash = bcoin.utils.revHex(tx.hash('hex'));
|
||||||
var ip = peer.socket.remoteAddress;
|
var ip = peer.socket.remoteAddress;
|
||||||
console.log(block);
|
console.log(tx);
|
||||||
console.log('Received transaction %s from %s.', hash, ip);
|
console.log('Received transaction %s from %s.', hash, ip);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open our ecdsa private key (our bitcoin address is derived from this)
|
// Open our ecdsa private key (our bitcoin address is derived from this)
|
||||||
// `priv` can be a hex string, a binary array, or a big number (bn.js)
|
// `priv` can be a hex string, a binary array, or a big number (bn.js)
|
||||||
|
var privkeyfile = process.env.HOME + '/.bcoin/priv';
|
||||||
|
if (!fs.existsSync(privkeyfile)) {
|
||||||
|
try {
|
||||||
|
var privkey = bcoin.wallet().getPrivateKey('base58');
|
||||||
|
fs.writeFileSync(privkeyfile, privkey);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log('Error creating private key file: '+err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var wallet = new bcoin.wallet({
|
var wallet = new bcoin.wallet({
|
||||||
priv: fs.readFileSync(process.env.HOME + '/.bcoin/priv'),
|
priv: fs.readFileSync(privkeyfile),
|
||||||
storage: pool.storage
|
storage: pool.storage
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user