Welcome to the Dash Forum!

Please sign up to discuss the most innovative cryptocurrency!

Detecting InstantSend transactions in a nodejs app.

Discussion in 'Miscellaneous Dash Guides' started by Antti Kaikkonen, Feb 8, 2019.

  1. Antti Kaikkonen

    Antti Kaikkonen Active Member

    Joined:
    Jun 20, 2017
    Messages:
    238
    Likes Received:
    157
    Trophy Points:
    103
    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.
     
    #1 Antti Kaikkonen, Feb 8, 2019
    Last edited: Feb 8, 2019
    • Like Like x 1
    • Friendly Friendly x 1
  2. Antti Kaikkonen

    Antti Kaikkonen Active Member

    Joined:
    Jun 20, 2017
    Messages:
    238
    Likes Received:
    157
    Trophy Points:
    103
    Dash Address:
    XnZdwT1w2kGeH6RujwoyJ7BBNrukdyTBRB

Share This Page