Detecting InstantSend transactions in a nodejs app.

Antti Kaikkonen

Active Member
Jun 20, 2017
258
170
103
dashradar.com
Dash Address
XnZdwT1w2kGeH6RujwoyJ7BBNrukdyTBRB
Prerequisites: node.js and npm, zeromq and of course Dash Core
1) Add this line to dash.conf:
Code:
zmqpubhashtxlock=tcp://127.0.0.1:28332
then restart dash-qt or dashd.

2) Create a new directory, navigate to the directory in terminal/command prompt and then run

Code:
npm install zeromq
this should create a new directory "node_modules"

3) Create a new file "instansend-recorder.js" with the following content
Code:
var zmq = require('zeromq');

var sock = zmq.socket('sub');
sock.connect('tcp://127.0.0.1:28332');
sock.subscribe('hashtxlock');

sock.on('message', function(topic, message) {
  let topicStr = topic.toString('ascii');
  if (topicStr === "hashtxlock") {
    let txid = message.toString('hex');
    console.log("Detected InstantSend transaction: ", txid, new Date());
    //Add custom logic here
  }
});
console.log("Started listening for InstantSend transactions");
4) run the app in terminal/command prompt
Code:
node instantsend-recorder.js
It will do nothing but print the txid and time when an InstantSend transaction is received. You can add your custom logic to for example process a payment.

Please note that if you don't have zeromq properly installed on your system, the application will still run but it doesn't detect any InstantSend transactions. You should test sending an InstantSend transaction to your own address to see if it will be properly detected.
 
Last edited:
  • Like
Reactions: UdjinM6