From af90d523e55527d4a4bfd6609a1d23520c055220 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sat, 29 Apr 2017 22:24:07 -0700 Subject: [PATCH] Updated README --- README.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f8472f1..c74d431 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 + } + }) }) ```