Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Apr 30, 2017
1 parent e69bee3 commit af90d52
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

This module encodes and decodes low-level network protocol data using streams.

You may want a higher-level module like [bitcoin-net](https://github.com/mappum/bitcoin-net/), which some things for you such as connection handshakes, sending keepalive pings, etc.

## Usage

`npm install bitcoin-protocol`
Expand All @@ -21,16 +23,33 @@ decoder.on('data', function (message) { console.log(message) })

var encoder = bp.createEncodeStream()

var socket = net.connect(8333, '127.0.0.1')
socket.pipe(decoder)
encoder.pipe(socket)

encoder.write({
magic: 0xd9b4bef9,
command: 'ping',
payload: {
nonce: new Buffer('0123456789abcdef', 'hex')
}
var socket = net.connect(8333, '127.0.0.1', function () {
socket.pipe(decoder)
encoder.pipe(socket)

encoder.write({
magic: 0xd9b4bef9,
command: 'version',
payload: {
version: 70012,
services: Buffer(8).fill(0),
timestamp: Math.round(Date.now() / 1000),
receiverAddress: {
services: Buffer('0100000000000000', 'hex'),
address: '0.0.0.0',
port: 8333
},
senderAddress: {
services: Buffer(8).fill(0),
address: '0.0.0.0',
port: 8333
},
nonce: Buffer(8).fill(123),
userAgent: 'foobar',
startHeight: 0,
relay: true
}
})
})
```

Expand Down

0 comments on commit af90d52

Please sign in to comment.