Bitcoin full node and query server

Dec 16, 2018

View in context in the libbitcoin Slack #general mirror.

Mr Hash11:57
@neillm hey i’ve added a couple of wiki pages to libbitcoin-server with JS client examples. I can’t pull request the wiki though so shall i send a git stash patch or something?
9 replies · neillm, Mr Hash · last Dec 17, 2018
neillm18:00
Cool, send me what you've got, I'd like to see it!
Mr Hash12:45
ok here’s a patch
js-wiki.patch Diff · 4.4 KB
diff --git a/Javascript-Query-Example.md b/Javascript-Query-Example.md
new file mode 100644
index 0000000..e333142
--- /dev/null
+++ b/Javascript-Query-Example.md
@@ -0,0 +1,75 @@
+### Fetch transaction:
+```js
+const zmq = require('zeromq');
+const pystruct = require('python-struct');
+const requester = zmq.socket('req');
+
+const endpoint = 'tcp://mainnet.libbitcoin.net:9091';
+
+requester.on('message', function(command, identifier, buffer) {
+  console.log(buffer.toString('hex').substr(8));
+  requester.close();
+});
+
+requester.setsockopt(zmq.ZMQ_RCVTIMEO, 5000);
+requester.setsockopt(zmq.ZMQ_SNDTIMEO, 5000);
+requester.connect(endpoint);
+
+const txhash = '60e030aba2f593caf913a7d96880ff227143bfc370d03dbaee37d582801ebd83';
+requester.send('blockchain.fetch_transaction2', zmq.ZMQ_SNDMORE);
+requester.send(pystruct.pack('I', 42), zmq.ZMQ_SNDMORE);
+requester.send(Buffer.from(txhash.match(/.{1,2}/g).reverse().join(''), 'hex'));
+
+```
+Output:
+```
+010000000181d06e4403b989d1e003def4944080e9537ef38e219f58a3856333050d72fe4a080000008b483045022100943e28772ef850587034b447a76c1eb918d63c82a4619a01a34cf32dee13807a02204cbe75c49f8ced0ebc373a6d8e7cb7ecab31369861d8997873b94bac13c379b3014104dbfb10dd8a498b3431f4c7041bbba82aa33146d40b7def4315e9e6df7424d527e762042f9fcc5450cbfc5f849bd3dace5cc9d9b3be8fadc3de92f96e303cf599ffffffff02a8101300000000001976a914b4dc57e35f93de9ec155872c1ad0136134fb08b188acbbe633000000000017a91461ec8bf07c6a3a04a08d1251d70178c1b3d273cc8700000000
+```
+
+### Fetch block header
+```js
+const zmq = require('zeromq');
+const pystruct = require('python-struct');
+const requester = zmq.socket('req');
+
full file
neillm19:17
Rather than a wiki page, maybe adding them to libbitcoin-server/data is appropriate, as that's where the python examples currently reside. Thoughts?
Mr Hash20:36
well there are a couple of examples in the wiki for python so i just copied that
Mr Hash20:36
but i don’t mind
Mr Hash20:36
i can add them as just js files
Mr Hash20:36
and submit a pull request
neillm20:37
Ah, you're right, I guess either way. It might be harder to keep the wiki documentation up to date than the files, although I expect they won't change that much
Mr Hash20:38
up to you, i’m easy either way, just let me know which you prefer